Insure++ Reference - LEAK_SCOPE
This error is generated whenever a function allocates memory for its
own use and then returns without freeing it or saving a pointer to the
block in an external variable. The allocated block can never be freed.
This code calls the function gimme , which allocates
a memory block that is never freed.
1: /*
2: * File: leakscop.c
3: */
4: #include <stdlib.h>
5:
6: void gimme()
7: {
8: char *p;
9: p = malloc(10);
10: return;
11: }
12:
13: main()
14: {
15: gimme();
16: return (0);
17: }
[leakscop.c:10] **LEAK_SCOPE**
1. >> return;
2. Memory leaked leaving scope: <return>
3. Lost block: 0x0003870 thru 0x00013879 (10 bytes)
block allocated at:
malloc() (interface)
gimme() leakscop.c, 9
main() leakscop.c, 15
Stack trace where the error occurred:
4. gimme() leakscop.c, 10
main() leakscop.c, 15
- Source line at which the problem was detected.
- Description of the problem and the block that is to be lost.
- Description of the block of memory that is about to be lost,
including its size and the line number at which it was allocated.
- Stack trace showing the function call sequence leading to the
error.
This problem usually results from an oversight on the part of the
programmer and is cured by simply freeing a block before returning from
a routine. In the current example, a call to free(p)
before line 10 would cure the problem.
A particularly easy way to generate this error is to return from the
middle of a routine, possibly due to an error condition arising, without
freeing previously allocated data. This bug is easy to introduce when
modifying existing code.
Some applications may be unable to free memory blocks and may not need
to worry about their permanent loss. To suppress these error messages in
this case add the option
insure++.suppress LEAK_SCOPE
to the .psrc file.
LEAK_RETURN
PARM_BAD_RANGE
|