Memory leaks can occur if your program allocates memory and then does not free it. For example, a resource leak can occur in a memory region that no longer has references from a process.
Consequences
Resource leaks generate the following runtime errors:
Detecting the error
This error would be trapped during the following circumstances:
Enabling error detection
In the IDE, you can expect the message for this type of memory error to include the following types of information and detail:
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 resource (memory) leaks
To address resource leaks in your program, ensure that memory is deallocated on all paths, including error paths.
Example
The following code shows an example of a memory leak:
int main(int argc, char ** argv){ char * str = malloc(10); if (argc>1) { str = malloc(20); // ... } printf("Str: %s\n",str); free(str); return 0; }