C ++免费错误,谁能帮帮我PLZ! [英] C++ free error , who can help me plz!
本文介绍了C ++免费错误,谁能帮帮我PLZ!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 ++;
继续;
}
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 < span class =code-keyword>> // 错误!!为什么?
return ret;
}
else {...
解决方案
< blockquote>最有可能在分配大小后修改内存。首先尝试不使用while循环来检查我的理论。
while (i<HMDetailNum)
while (i< AreaShopListNum)
如果您学会使用调试器,它会有很多帮助也许添加一些断言。
在free
之前,你将指针传递给另一个函数,TimeRoutingW
- 也许该函数已经释放了它?
如果这没有帮助,请发布您收到的错误消息。它可能包含重要的线索。
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 { ...
解决方案
most likely you modify the memory after the allocated size. Try it first without the while loop to check my theory.
while (i <HMDetailNum)
while (i < AreaShopListNum)
It will help lots if you learn to use the debugger and perhaps add some asserts.
Immediately before thefree
, 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.
这篇关于C ++免费错误,谁能帮帮我PLZ!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文