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 - EXPR_DANGLING



EXPR_DANGLING

Expression uses dangling pointer

This error is generated whenever an expression operates on a dangling pointer - i.e., one which points to either

  • A block of dynamically allocated memory that has already been freed.
  • A block of memory which was allocated on the stack in some routine that has subsequently returned.

Problem

The following code fragment shows a block of memory being allocated and then freed. After the memory is de-allocated, the pointer to it is used again, even though it no longer points to valid memory.


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

Diagnosis (at runtime)


	[expdangl.c:12] **EXPR_DANGLING**
1.	>> 		if(a > b)
	
2.		Expression uses dangling pointer: a > b
	
3.		Pointer		: 0x00013868
		In block	: 0x00013868 thru 0x00013871 (10 bytes)
				     block allocated at:
					malloc() (interface)
					  main() expdangl.c, 8

			stack trace where memory was freed:
					  main() expdangl.c, 11
	
4.		Stack trace where the error occurred:
					  main() expdangl.c, 12


  1. Source line at which the problem was detected.
  2. Description of the problem and the expression that is in error.
  3. Description of the memory block to which the pointer used to point, including the location at which it was allocated and subsequently freed.
  4. Stack trace showing the function call sequence leading to the error.

Repair

A good first check is to see if the pointer used in the expression at the indicated line is actually the one intended.

If it appears to be the correct pointer, check the line of code where the block was freed (as shown in the error message) to see if it was freed incorrectly.


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