Dynamically allocated memory was not freed.
Memory leaks are detected when the last pointer to a piece of dynamically allocated memory is destroyed without that value having been freed. Pointer values are destroyed when the variable is overwritten or when its declaration goes out of scope, either by leaving a subroutine or a block.
ID |
Observation |
Description |
---|---|---|
1 |
Memory leak |
The place the memory was leaked |
2 |
Allocation site |
The place the memory was allocated |
#include <stdlib> char *p1; void f() { char *p2; p1 = (char *)malloc(10); // allocated here p2 = p1; p1 = 0; // value in p1 is destroyed, but memory is not leaked yet, // because p2 still contains address and p2 could be freed *p2 = 'a'; // memory is leaked here because p2 is destroyed when f returns }
Copyright © 2010, Intel Corporation. All rights reserved.