Insure++ Reference - WRITE_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: writdngl.c
3: */
4: #include <stdlib.h>
5:
6: main()
7: {
8: char *a = (char *)malloc(10);
9:
10: free(a);
11: *a = 'x';
12: return (0);
13: }
[writdngl.c:11] **WRITE_DANGLING**
1. >> *a = 'x';
2. Writing to a dangling pointer: a
3. Pointer: 0x000173e8
4. In block: 0x000173e8 thru 0x000173f1 (10 bytes)
block allocated at:
malloc() (interface)
main() writdngl.c, 8
5. stack trace where memory was freed:
main() writdngl.c, 10
6. Stack trace where the error occurred:
main() writdngl.c, 11
**Memory corrupted. Program may crash!!**
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Value of the dangling pinter variable.
- Description of the block to which this pointer used to point,
including its size, name, and the line at which it was allocated.
- Indication of the line at which 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.
WRITE_BAD_INDEX
WRITE_NULL
|