Sunday, January 3, 2010

free() causes C++ program to crash

The free() function is used as a means for
explicitly telling the C++ compiler to delete
the memory allocated to the pointer passed
as an argument in the free() function.

A typical type of crash can occur if
free() is called on a pointer to which
memory is not allocated or when the pointer
is not initialized. In this case, the pointer
points to an invalid memory location resulting
in a fatal error when trying to free memory
allocated at that location.

To remedy this problem, please verify if the
pointer is being correctly initialized by putting
appropriate checks.


Post a Comment