Insure++ Reference - LEAK_RETURN
This error is generated whenever a function returns a pointer to a block
of memory which is then ignored by the calling routine. In this case, the
allocated memory block is permanently lost and can never be freed.
This code calls the function gimme , which returns a
memory block that is subsequently ignored by the main routine.
1: /*
2: * File: leakret.c
3: */
4: #include <stdlib.h>
5:
6: char *gimme()
7: {
8: return malloc(10);
9: }
10:
11: main()
12: {
13: gimme();
14: return (0);
15: }
[leakret.c:8] **LEAK_RETURN**
1. >> gimme();
2. Memory leaked ignoring return value: <return>
3. Lost block: 0x000173e8 thru 0x000173f1 (10 bytes)
block allocated at:
malloc() (interface)
gimme() leakret.c, 8
main() leakret.c, 13
Stack trace where the error occurred:
main() leakret.c, 13
- 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.
This problem usually results from an oversight on the part of the
programmer, or a misunderstanding of the nature of the pointer returned
by a routine. In particular, it is sometimes unclear whether the value
returned points to a static block of memory, which will not need to be
freed, or a dynamically allocated one, which should be.
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_RETURN
to the .psrc file.
LEAK_FREE
LEAK_SCOPE
|