Insure++ Reference - READ_DANGLING
This problem occurs when an attempt is made to dereference a pointer
that points to a block of memory that has been freed.
This code attempts to use a piece of dynamically allocated memory
after it has already been freed.
1: /*
2: * File: readdngl.c
3: */
4: #include <stdlib.h>
5:
6: main()
7: {
8: char b;
9: char *a = (char *)malloc(10);
10:
11: free(a);
12: b = *a;
13: return (0);
14: }
[readdngl.c:12] **READ_DANGLING**
1. >> b = *a;
2. Reading from a dangling pointer: a
3. Pointer: 0x000173e8
4. In block: 0x000173e8 thru 0x000173f1 (10 bytes)
block allocated at:
malloc() (interface)
main() readdngl.c, 9
5. stack trace where memory was freed:
main() readdangl.c, 11
Stack trace where the error occurred:
6. main() readdangl.c, 12
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Value of the dangling pointer variable.
- Description of the block to which this pointer used to point,
including its size, name and the line at which it was allocated.
- Stack trace showing where this block was freed.
- Stack trace showing the function call sequence leading to the
error.
Check that the de-allocation that occurs at the indicated location
should, indeed, have taken place. Also check that the pointer you are
using should really be pointing to a block allocated at the indicated
place.
READ_BAD_INDEX
READ_NULL
|