The illegal deallocation of memory occurs when a free() operation is performed on a pointer that doesn't point to an appropriate heap memory segment. This type of error can occur when you attempt to do any of the following activities:
Consequences
The illegal deallocation of memory can generate the following runtime errors:
Detecting the error
In the QNX IDE, the Memory Analysis tool detects this error (if error detection is enabled), and it traps the illegal deallocation error when any of the following functions are called:
Enabling error detection for the illegal deallocation of memory
To enable error detection for the illegal deallocation of memory:
Message returned to the QNX IDE
In the IDE, you can expect the message for this type of memory error to include the following types of information and detail:
For a list of error messages returned by the Memory Analysis tool, see Summary of error messages for Memory Analysis.
How to address the illegal deallocation of memory
To help address this memory problem, try the following:
Example
The following code shows an example of the illegal deallocation of memory:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char ** argv){ char * str = ""; if (argc>1) { str = malloc(10); // ... } printf("Str: %s\n",str); free(str); return 0; }