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



READ_DANGLING

Reading from a dangling pointer

This problem occurs when an attempt is made to dereference a pointer that points to a block of memory that has been freed.

Problem

This code attempts to use a piece of dynamically allocated memory after it has already been freed.

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

Diagnosis (at runtime)

	[readdngl.c:12] **READ_DANGLING**
1.	>> 		b = *a;
	
2.		Reading from a dangling pointer: a
	
3.		Pointer:	0x000173e8
4.		In block:	0x000173e8 thru 0x000173f1 (10 bytes)
				block allocated at:
				     malloc() (interface)
				       main() readdngl.c, 9
	
5.				stack trace where memory was freed:
				       main() readdangl.c, 11

		Stack trace where the error occurred:
6.			               main() readdangl.c, 12

  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 dangling pointer variable.
  4. Description of the block to which this pointer used to point, including its size, name and the line at which it was allocated.
  5. Stack trace showing where this block was freed.
  6. Stack trace showing the function call sequence leading to the error.

Repair

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.


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