In this section:
This error is generated when a memory block is freed multiple times.
|
The following code frees the same pointer twice.
/* * File: freedngl.c */ #include <stdlib.h> main() { char *a = (char *)malloc(10); free(a); free(a); return (0); } |
[freedngl.c:10] **FREE_DANGLING** >> free(a); Freeing dangling pointer: a ---- Associated Common Weakness Enumerations ---- CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer CWE-416: Use after free CWE-825: Expired pointer dereference Pointer : 0x000173e0 In block : 0x000173e0 thru 0x000173e9 (10 bytes) block allocated at: malloc() (interface) main() freedngl.c, 8 stack trace where memory was freed: main() freedngl.c, 9 Stack trace where the error occurred: main() freedngl.c, 10 **Memory corrupted. Program may crash!!** |
Some systems allow memory blocks to be freed multiple times. However, this is not portable and is not a recommended practice.
The information supplied in the diagnostics will allow you to see the line of code which previously deallocated this block of memory. You should attempt to remove one of the two calls.
If your application is unable to prevent multiple calls to deallocate the same block, you can suppress error messages by suppressing FREE_DANGLING
.
The table below shows Common Weakness Enumerations associated with this error.
CWE | Description |
---|---|
CWE-119 | Improper Restriction of Operations within the Bounds of a Memory Buffer |
CWE-416 | Use after free |
CWE-825 | Expired pointer dereference |