Hello,
I have a module as shown below:
This memory had been previously allocated using the new operator.Code:void FreeMemory(void *mem) { delete mem; }
When I was running a unit testing tool for this function, the program crashes on the delete operator. It actually passes a pointer which was not allocated previously using new operator.
I read that the new operator, gives an exception if it fails to allocate memory.Code:char *p; FreeMemory(p);
However, the delete operator does not raise an exception and simply crashes.
Now, how do I get around this problem and make sure the test case passes successfully ?
Any suggestions?
Thanks