Debugging Memory Problems with MemoryScape
:
Chapter 1 Locating Memory Problems
:
Event and Error Notification
:
Types of Problems
:
Freeing the Wrong Address
Freeing the Wrong Address
MemoryScape can detect when a program tries to free a block that does not correspond to the start of a block allocated using the
malloc()
function. The following program illustrates this problem:
int main (int argc, char *argv[])
{
char *s, *misaligned_s;
/* Get some memory */
s = malloc(sizeof(int)*64));
/* Release memory using a misaligned address */
misaligned_s = s + 8;
free(misaligned_s);
free(s);
return 0;
}