Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!eecae!cps3xx!usenet From: usenet@cps3xx.UUCP (Usenet file owner) Newsgroups: comp.sys.amiga.tech Subject: Re: Catching free memory violations Keywords: FreeMem monitor debug memory spam Message-ID: <3965@cps3xx.UUCP> Date: 28 Jul 89 00:50:05 GMT References: <7408@ecsvax.UUCP> Reply-To: porkka@frith.UUCP (Joe Porkka) Organization: Michigan State University Lines: 33 In article <7408@ecsvax.UUCP> utoddl@ecsvax.UUCP (Todd M. Lewis) writes: > >I have a program which seems to use memory it doesn't own >from time to time, and I'd like some way to catch it in the act. >I've been thinking about a method to see if/when it messes up free >memory, and I'd like to know why this wouldn't work: > > * Zap FreeMem() to zero out memory whenever it is freed. > * Zero out all memory which is already freed. > * Periodically scan all free memory to see if it is still > zero'd out. If it isn't, report the address range that > has been munged (so you know about it) and optionally > zero that RAM (and see who dies:). SOunds good. Easy way to Zap FreeMem is make a function called "freemem" and then for every other module in the program, #define FreeMem freemem To help solve my memory trashing problems, I have sometimes replace AllocMem & FreeMem with the above method with routines that did the same, but tracked each Alloc and Free. The FreeMem routine would print an error (with name of the function that called it) if something tried to free an unalloced block or a block of the wrong size. TO help debugging without rebooting, then you can run thru your memory alloc list and actually free blocks that did not otherwise get freed. If your memory mismangement is more complicated than messing up Alloc/Free, then I suggest as a first cut to just check memory that you have used then freed. REAL NAME: Joe Porkka jap@frith.cl.msu.edu