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



HEAP_CORRUPT

The heap is corrupt

This error is generated when Insure++ detects that the heap has been corrupted. These messages can only be generated if the malloc_replace option is on.

Typically, Insure++ will identify a serious problem before it corrupts the heap. If the corruption occurs in code which was not compiled with Insure++, however, it may not be found for a while. Hopefully, you will discover that the problem is in a file for which you have source code. If this is the case, you can recompile that file with Insure++ and continue debugging.

Problem

One simple way to generate this error is to corrupt memory in a routine not compiled with Insure++.

Compile the program with your normal compiler and link it with Insure++, e.g.

	cc -g -c heapbad.c
	insure -g -o heapbad heapbad.o
	./heapbad


	1:	/*
	2:	 * heapbad.c
	3:	 */
	4:	#include <malloc.h>
	5:
	6:	main() {
	7:		int i;
	8:		char *c = (char *) malloc(10);
	9:
	10:		for (i = 10; i < 20; i++)
	11:		c[i] = 'a';
	12:		free(c); bug
	13:	}

Diagnosis (at runtime)


1.	[malloc.c:1151] **HEAP_CORRUPT**
	
2.		Pointers between this and adjoining blocks are invalid.
	
3.		Corrupt block : 0x00049928 thru 0x00049ab8 (401 bytes)
	
		The chain was last validated at the following stack trace:
				malloc()	malloc.c, 532
		  _Insure++_alloc_stack()
		      _Insure++_assignb()
		_Insure++_direct_malloc()
				malloc()	malloc.c, 670
4.				  main()	heapbad.c, 8
	
5.	Bus error (core dumped)


  1. Source line at which the problem was detected.
  2. Description of the problem - this may or may not be particularly useful.
  3. A description of the block at which the error was detected. This block may or may not be the cause of the error.
  4. Stack trace showing the last time the heap was checked and found to be okay.
  5. Core dumps typically follow these messages, as any usage of the dynamic memory functions will be unable to cope.

Repair

Since the above message seemed to occur in the file heapbad.c, which was not processed with Insure++, the simplest thing to do is process this file with Insure++.

	insure -g -o heapbad heapbad.c

In this case, the bug is quickly identified as a WRITE_BAD_INDEX, and can be repaired accordingly.


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