Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - FREE_DANGLING



FREE_DANGLING

Freeing dangling pointer

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

Problem

The following code frees the same pointer twice.


	1:	/*
	2:	 * File: freedngl.c
	3:	 */
	4:	#include <stdlib.h>
	5:	
	6:	main()
	7:	{
	8:		char *a = (char *)malloc(10);
	9:		free(a);
	10:		free(a); bug
	11:		return (0);
	12:	}

Diagnosis (at runtime)


	[freedngl.c:10] **FREE_DANGLING**
1.	>> 		free(a);
	
2.		Freeing dangling pointer: a
	
3.		Pointer	   : 0x000173e0 
		In block   : 0x000173e0 thru 0x000173e9 (10 bytes)
			   block allocated at: 
4.				malloc() (interface)
			  	  main() freedngl.c, 8

5.			stack trace where memory was freed:
				  main() freedngl.c, 9

6.		Stack trace where the error occurred:
				  main() freedngl.c, 10

7.		**Memory corrupted. Program may crash!!**


  1. Source line at which the problem was detected.
  2. Description of the problem and the expression that is in error.
  3. Value of the pointer that is being deallocated.
  4. Information about the block of memory addressed by this pointer, including information about where this block was allocated.
  5. Stack trace showing where this block was freed.
  6. Stack trace showing the function call sequence leading to the error.
  7. 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 de-allocated 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 adding the option

	insure++.suppress FREE_DANGLING

to the .psrc file.


< FREE_BODY > FREE_GLOBAL
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft