In this section:

Overview

This error is generated when a memory block is freed multiple times.

CodeDescriptionEnabledReportedPlatform
FREE_DANGLING

Freeing dangling pointer

(tick)RuntimeWindows/Unix


Problem

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);
}

Diagnosis at Runtime

[freedngl.c:10] **FREE_DANGLING**
>> 			free(a);
Freeing dangling pointer: a
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!!**
  • Line 2: Source line at which the problem was detected.
  • Line 3: Description of the problem and the expression that is in error.
  • Line 4: Value of the pointer that is being deallocated.
  • Line 6: Information about the block of memory addressed by this pointer, including information about where this block was allocated.
  • Line 9: Stack trace showing where this block was freed.
  • Line 11: Stack trace showing the function call sequence leading to the error.
  • Line 13: Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

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 in the Suppressions Control Panel.

  • No labels