Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (bFullCourse) {
        long AreaShopListNum = 0;

        if (piAreaInfo->SPKBN == 0)
            AreaShopListNum = HMDetailNum - 2;
        else
            AreaShopListNum = HMDetailNum - 3;

        AreaShopList_T *piAreaShopList = (AreaShopList_T*)malloc(sizeof(AreaShopList_T) * AreaShopListNum);

        int i = 0;
        HMDetail_T* pHMDetail = pioHMDetail;
        AreaShopList_T *pAreaShopList = piAreaShopList;
        while (i < HMDetailNum) {
            if (strcmp(piBaseInfo->BaseCD, pHMDetail->DlvCD) == 0) {
                i++;
                pHMDetail++;
                continue;
            }
            strcpy_s(pAreaShopList->HonNO, pHMDetail->HonNO);
            strcpy_s(pAreaShopList->ShopCD, pHMDetail->DlvCD);

            i++;
            pHMDetail++;
            pAreaShopList++;
        }

        int ret = TimeRoutingW(piBaseInfo, ShopInfoNum, piShopInfo, 1, piAreaInfo, AreaShopListNum, piAreaShopList,
                                pioHMDetail, pszOutputFile, false, bCvs, bWeekExchange);

        <big>free(piAreaShopList);</big>    // error !! why?

        return ret;
    }
    else { ...
Posted

most likely you modify the memory after the allocated size. Try it first without the while loop to check my theory.
 
Share this answer
 
Comments
LaviLiu 26-May-15 6:01am    
i try it , then without while loop is ok, then? (my english is not good)
C++
while (i < HMDetailNum) 


C++
while (i <  AreaShopListNum)


It will help lots if you learn to use the debugger and perhaps add some asserts.
 
Share this answer
 
v3
Comments
LaviLiu 26-May-15 6:25am    
I try it but without effect
[no name] 26-May-15 6:31am    
That is one error for sure of possibly many. The code is not high quality. Now did you read the next line. Time for you to take the next step.
Immediately before the free, you pass the pointer to another function, TimeRoutingW - maybe that function already frees it?

If that doesn't help, please post the error message that you get. It may contain important clues where to look.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900