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_WILD



FREE_WILD

Freeing wild pointer

This error is generated when memory is de-allocated that is unknown to Insure++.

This can come about in two ways:

  • Errors in user code that result in pointers that don't point at any known memory block.
  • Compiling only some of the files that make up an application. This can result in Insure++ not knowing enough about memory usage to distinguish correct and erroneous behavior.
Bend This discussion centers on the first type of problem described here. A detailed discussion of the second topic, including samples of its generation and repair can be found in "Interfaces".

Problem

A particularly unpleasant problem can occur when using union types. The following code first assigns the pointer element of a union but then overwrites it with another element before finally attempting to free the initial memory block.


	1:	/*
	2:	 * File: freewild.c
	3:	 */
	4:	#include <stdlib.h>
	5:
	6:	union {
	7:		int *ptr;
	8:		int ival;
	9:	} u;
	10:
	11:	main()
	12:	{
	13:		char *a = (char *)malloc(100);
	14:
	15:		u.ptr = a;
	16:		u.ival = 123;
	17:		free(u.ptr); bug
	18:		return (0);
	19:	}

Diagnosis (at runtime)


	[freewild.c:17] **FREE_WILD**
1.	>> 		free(u.ptr);
	
2.		Freeing wild pointer: u.ptr
	
3.		Pointer : 0x0000007b
	
		Stack trace where error occurred:
4.				main() freewild.c, 17


  1. Source line at which the problem was detected.
  2. Description of the problem and the name of the parameter that is in error.
  3. Value of the bad pointer.
  4. Stack trace showing the function call sequence leading to the error.

Repair

This problem is most conveniently tracked in a debugger by stopping the program at the indicated source line. You should then examine the illegal value and attempt to see where it was generated. Alternatively you can stop the program at some point prior to the error and single-step through the code leading up to the problem.

"Wild pointers" can also be generated when Insure++ has only partial information about your program's structure. This issue is discussed extensively in "Interfaces".


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