runtime error due to corruption of heap
-
Hi Guys!, I'm getting a runtime error, and compiler is pointing at "free.c", shown below:
void __cdecl _free_base (void * pBlock)
{int retval = 0; if (pBlock == NULL) return; RTCCALLBACK(\_RTC\_Free\_hook, (pBlock, 0)); retval = HeapFree(\_crtheap, 0, pBlock); if (retval == 0) { errno = \_get\_errno\_from\_oserr(GetLastError()); }
}
I couldn't troubleshoot where exactly is the issue.. It would be of great help if you can give some suggestions.. Thanks!
-
Hi Guys!, I'm getting a runtime error, and compiler is pointing at "free.c", shown below:
void __cdecl _free_base (void * pBlock)
{int retval = 0; if (pBlock == NULL) return; RTCCALLBACK(\_RTC\_Free\_hook, (pBlock, 0)); retval = HeapFree(\_crtheap, 0, pBlock); if (retval == 0) { errno = \_get\_errno\_from\_oserr(GetLastError()); }
}
I couldn't troubleshoot where exactly is the issue.. It would be of great help if you can give some suggestions.. Thanks!
This is my main program..I'm sorry to post whole bunch of code here!, but I'm wondering this may helps someone can pointout the issue
int main(int argc, char* argv[])
{char fname\[30\]; char fpath\[100\]; // file name for logging char fpath1\[100\]; // file name for logging char fpath2\[100\]; // implimentation for genrating force enable bool array memset(boolArray,0,sizeof(bool)\*arraySize); bool \*pBool =boolArray + 10; srand( (unsigned)time(NULL)); int rIndex2; for(int i=0;i<10;++i){ memset(pBool,1,sizeof(bool)\*12); //memset(pBool,1,sizeof(bool)); int rIndex = rand()%12; pBool\[rIndex\]=0; do{ //int rIndex2; rIndex2 = rand()%12; pBool\[rIndex2\]=0; } while (rIndex2==rIndex); //pBool = rand()%2; pBool +=12; } for (int j=0; jgetNumDevices(); // limit the number of devices to MAX\_DEVICES numHapticDevices = cMin(numHapticDevices, MAX\_DEVICES); //----------------------------------------------------------------------- // 3D - SCENEGRAPH //----------------------------------------------------------------------- //Seperated into two if s
-
Hi Guys!, I'm getting a runtime error, and compiler is pointing at "free.c", shown below:
void __cdecl _free_base (void * pBlock)
{int retval = 0; if (pBlock == NULL) return; RTCCALLBACK(\_RTC\_Free\_hook, (pBlock, 0)); retval = HeapFree(\_crtheap, 0, pBlock); if (retval == 0) { errno = \_get\_errno\_from\_oserr(GetLastError()); }
}
I couldn't troubleshoot where exactly is the issue.. It would be of great help if you can give some suggestions.. Thanks!
This sort of error is caused by code overwriting the beginning (or end) of a heap block, and corrupting the heap control structures. One way to find such a problem is to wrap each of your blocks in a "signature" (see below), and periodically check that the "signature" is valid. Original structure:
class foo
{
int baz;
char bar;
};New structure:
class foo
{
long sig1;
int baz;
char bar;
long sig2;
};Note that you can use the constructor to initialize the signature, and the destructor to check whether the signatures have changed. Your methods can check the validity of the signatures before performing any operations. You can also modify the signatures in the destructor, in order to catch accesses to freed memory. A library of this sort is a basic tool for any C++ programmer. If you don't have such a library in your toolbox - write one!
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill
-
This is my main program..I'm sorry to post whole bunch of code here!, but I'm wondering this may helps someone can pointout the issue
int main(int argc, char* argv[])
{char fname\[30\]; char fpath\[100\]; // file name for logging char fpath1\[100\]; // file name for logging char fpath2\[100\]; // implimentation for genrating force enable bool array memset(boolArray,0,sizeof(bool)\*arraySize); bool \*pBool =boolArray + 10; srand( (unsigned)time(NULL)); int rIndex2; for(int i=0;i<10;++i){ memset(pBool,1,sizeof(bool)\*12); //memset(pBool,1,sizeof(bool)); int rIndex = rand()%12; pBool\[rIndex\]=0; do{ //int rIndex2; rIndex2 = rand()%12; pBool\[rIndex2\]=0; } while (rIndex2==rIndex); //pBool = rand()%2; pBool +=12; } for (int j=0; jgetNumDevices(); // limit the number of devices to MAX\_DEVICES numHapticDevices = cMin(numHapticDevices, MAX\_DEVICES); //----------------------------------------------------------------------- // 3D - SCENEGRAPH //----------------------------------------------------------------------- //Seperated into two if s
Why not remove everything that is not related to the problem, as it is just noise. Then we can look at what's left and make suggestions.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Hi Guys!, I'm getting a runtime error, and compiler is pointing at "free.c", shown below:
void __cdecl _free_base (void * pBlock)
{int retval = 0; if (pBlock == NULL) return; RTCCALLBACK(\_RTC\_Free\_hook, (pBlock, 0)); retval = HeapFree(\_crtheap, 0, pBlock); if (retval == 0) { errno = \_get\_errno\_from\_oserr(GetLastError()); }
}
I couldn't troubleshoot where exactly is the issue.. It would be of great help if you can give some suggestions.. Thanks!
This is usually sourced by writing to an array with an out of bound index. So you must check all your allocated arrays (which may include arrays that are allocated by library functions). Starting with your own ones, search for any call to
new
as array; e.g.:type arrayName = new type[size];
Then for each array check the accesses for invalid indexes (index < 0 or >= size). You can do this manually by reading your source or by guarding all accesses with assertions in debug builds:
assert(index > 0 && index < arrayNameSize);
arrayName[index] = someValue;Your posted code does not contain the allocation of most. So it can't be checked by us. But there are many candidates:
boolArray
and all arrays used inside the 'while (i < numHapticDevices)' loop (e.g.hapticDevices
).