🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6912

Re: Borland C++'s "heapcheck" function

#6912
From: Charles McClellan
Date: Fri, 31 May 1991 18:53
42 lines
2313 bytes
In article <m0jizjG-0001OzC@dharma.reed.edu>, minar@reed.edu writes:
> In article <1991May30.090835.9320@uwovax.uwo.ca> 35004_240@uwovax.uwo.ca (Charles McClellan) writes:
> 
>>These functions will basically catch most cases where you continue
>>to use a pointer after freeing it.  Heapfillfree and heapcheckfree will also 
>>catch memory overwrites of the heap.
> 
> how does it do that? What does it do, exactly?

To the best of my knowledge the way heapcheck() works is this:

the malloc functions keep a linked list of free and allocated blocks. The 
header for each block contains among other things the size of the block
and the pointer to the next block. Heapcheck() walks this list checking that 
each header contains reasonable values.  

Heapfillfree() enables you to fill all free blocks on the list with 
an arbritrary value.  Heapcheckfree() then checks to see if all free values
still have this value.  Thus if you continue to use a pointer after
freeing it, the fill value will probably be changed.  The fill value
can also be changed if you have a wild pointer that is writing over
parts of the heap.

For these functions to be useful, you must call them before and after
every use of malloc() and free().  This is easiest if you provide
your own replacements for them.  This was discussed in a couple of
articles in the August 1990 Dr. Dobbs.  And I have since seen a commercial
library advertised that replaces calls to malloc() and free() with
error checking versions. 

By themselves Heapcheck() and company are not that useful, but when
used in error checking versions of malloc() etc, I have found them
to be very useful.


-- 
Charles McClellan:	SLIS
			Elborn College
			University of Western Ontario
			London, Ont.  Canada
			Tel:  519-661-3542  ext. 8485
			C.McClellan@uwovax.uwo.ca
Technical Details
Message-ID: <1991May31.135326.9331@uwovax.uwo.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!ria!uwovax.uwo.ca!35004_240
References: <0094956C.49369EA0@MAPLE.CIRCA.UFL.EDU> <1991May30.090835.9320@uwovax.uwo.ca> <m0jizjG-0001OzC@dharma.reed.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!ria!uwovax.uwo.ca!35004_240
From: 35004_240@uwovax.uwo.ca (Charles McClellan)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Borland C++'s "heapcheck" function
Message-ID: <1991May31.135326.9331@uwovax.uwo.ca>
Date: 31 May 91 18:53:26 GMT
References: <0094956C.49369EA0@MAPLE.CIRCA.UFL.EDU> <1991May30.090835.9320@uwovax.uwo.ca> <m0jizjG-0001OzC@dharma.reed.edu>
Lines: 42