In this section:

Overview

This error is generated when memory is de-allocated that is unknown to Insure++. This can occur for two reasons:

  • There are errors in your code that result in pointers that don’t point at any known memory block.
  • Only some of the files that make up an application are compiled. As a result, Insure++ will not have enough information about memory usage to distinguish correct and erroneous behavior.

This section focuses on the first type of problem described. For information on the second type of problem, contact Parasoft's Quality Consultants.

CodeDescriptionEnabledReportedPlatform
FREE_WILD

Freeing wild pointer

(tick)RuntimeWindows/Unix


Problem

The following code first assigns the pointer element of a union type but then overwrites it with another element before finally attempting to free the initial memory block.

/*
 * File: freewild.c
 */
#include <stdlib.h>

union {
	int *ptr;
	int ival;
} u;

main()
{
	char *a = (char *)malloc(100);

	u.ptr = a;
	u.ival = 123;
	free(u.ptr);
	return (0);
}

Diagnosis at Runtime

[freewild.c:17] **FREE_WILD**
>>		 free(u.ptr);
Freeing wild pointer: u.ptr
Pointer : 0x0000007b
Stack trace where error occurred:
			main() freewild.c, 17
  • Line 2: Source line at which the problem was detected.
  • Line 3: Description of the problem and the name of the parameter that is in error.
  • Line 4: Value of the bad pointer.
  • Line 6: 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++ does not have enough information about your program’s structure. Contact Parasoft's Quality Consultants for more information on this topic.

  • No labels