Insure++ Reference - EXPR_DANGLING
This error is generated whenever an expression operates on a dangling
pointer - i.e., one which points to either
- A block of dynamically allocated memory that has already been
freed.
- A block of memory which was allocated on the stack in some routine
that has subsequently returned.
The following code fragment shows a block of memory being allocated
and then freed. After the memory is de-allocated, the pointer to it is
used again, even though it no longer points to valid memory.
1: /*
2: * File: expdangl.c
3: */
4: #include <stdlib.h>
5:
6: main()
7: {
8: char *a = (char *)malloc(10);
9: char b[10];
10:
11: free(a);
12: if(a > b)
13: a = b;
14: return (0);
15: }
[expdangl.c:12] **EXPR_DANGLING**
1. >> if(a > b)
2. Expression uses dangling pointer: a > b
3. Pointer : 0x00013868
In block : 0x00013868 thru 0x00013871 (10 bytes)
block allocated at:
malloc() (interface)
main() expdangl.c, 8
stack trace where memory was freed:
main() expdangl.c, 11
4. Stack trace where the error occurred:
main() expdangl.c, 12
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Description of the memory block to which the pointer used to
point, including the location at which it was allocated and
subsequently freed.
- Stack trace showing the function call sequence leading to the
error.
A good first check is to see if the pointer used in the expression
at the indicated line is actually the one intended.
If it appears to be the correct pointer, check the line of code where
the block was freed (as shown in the error message) to see if it was
freed incorrectly.
EXPR_BAD_RANGE
EXPR_NULL
|