Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!oliveb!sun!pepper!cmcmanis
From: cmcmanis%pepper@Sun.COM (Chuck McManis)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Memory Freed Twice guru
Message-ID: <70075@sun.uucp>
Date: 26 Sep 88 05:27:42 GMT
References: <12741@cisunx.UUCP>
Sender: news@sun.uucp
Reply-To: cmcmanis@sun.UUCP (Chuck McManis)
Organization: Sun Microsystems, Mountain View
Lines: 37

In article <12741@cisunx.UUCP> (Eric J. Kennedy) writes:
>Every time, the program does all of the above, prints out the *right*
>*answer*, and crashes.  Guru 81000009, memory freed twice.  Using Manx db,
>it always crashes in __FreeMem, with some impossibly huge value being in
>D0, which is supposed to be the amount of memory to free.  (Gosh, I sure
>wish I had 1.2 Gigabytes of ram so I could free it!)
>
>I'm using Manx 3.4a.  It does this under all memory models, 16 or 32 bit
>ints, manx or amiga ieee libraries, with or without explicitly freeing
>the memory in the program, and using malloc() and free() or AllocMem()
>and FreeMem().
>
>Ok, you say.  I've got a bug in the program.  _But_ the program comes
>up with the right answer!!  And it works perfectly on an MS-DOS
>machine.  So what's going on?

Welcome to the Amiga! Where real program bugs cause real program crashes!
(No, I'm not being cruel its one of those things that is nice about the 
Amiga) You see, your memory allocation bug is in the MS-DOS version too
but MS-DOS does the equivalent of a reboot when a program exits. This 
restores memory and you are never the wiser! This behaviour can cover up
a lot of sins and of course on the Amiga you can't get away with it
because these kinds of errors cause other programs to crash. 

Anyway, to track it, there was a program on the developers disk called
"snoop" that used to print out memory allocations and deallocations,
combined with some printfs() it can be used to track this problem.
It was a really simple SetFunction of the exec vectors. Anyway,
the fact that you get the correct answer can only be used to identify 
that the memory problem happens sometime past the point where it generates
the results. You might also check the memlist before you call free to
see if it has been stomped on.


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.