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



WRITE_DANGLING

Writing to 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: writdngl.c
	3:	 */
	4:	#include <stdlib.h>
	5:	
	6:	main()
	7:	{
	8:		char *a = (char *)malloc(10);
	9:
	10:		free(a);
	11:		*a = 'x'; bug
	12:		return (0);
	13:	}

Diagnosis (at runtime)

	[writdngl.c:11] **WRITE_DANGLING**
1.	>> 		*a = 'x';
	
2.		Writing to a dangling pointer: a
	
3.		Pointer:   0x000173e8
4.		In block:  0x000173e8 thru 0x000173f1 (10 bytes)
			   block allocated at:
				malloc() (interface)
				  main() writdngl.c, 8
5.			   stack trace where memory was freed:
				  main()  writdngl.c, 10

6.		Stack trace where the error occurred:
				  main() writdngl.c, 11
	
		**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 dangling pinter 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. Indication of the line at which 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.


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