delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/28/12:04:45

Message-Id: <199910281314.QAA02695@ankara.Foo.COM>
From: "S. M. Halloran" <mitch AT duzen DOT com DOT tr>
Organization: User RFC 822- and 1123-compliant
To: Peter Danielsson <e96pd AT efd DOT lth DOT se>
Date: Thu, 28 Oct 1999 17:22:05 +0200
MIME-Version: 1.0
Subject: Re: Crashes on free()
CC: djgpp AT delorie DOT com
In-reply-to: <38183AB5.BDE66A18@efd.lth.se>
X-mailer: Pegasus Mail for Win32 (v3.12)
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 28 Oct 99, Peter Danielsson was found to have commented thusly:

> Why in h-ll does my program crash? It crashes on free() and it is not
> even in my functions (I just malloc and does not free at all). Sometimes

Well, if the function in which you call malloc() is one that is frequently 
called, and you never call free(), it is easy to see why it crashes:

1. you are probably not testing the pointer returned by malloc() to see if 
it is NULL...a sure bet you are leaking memory...but trying to use the 
pointer anyway...crash!

2. system calls that depend upon malloc() should be have their return 
values tested, and if errors, the error possibily revealed in errno (check 
to see if errno == ENOMEM...wanna bet?)

3. Every call to malloc()/calloc(), on principle, should be matched by a 
call to free() somewhere, and usually at the same block level, some of the 
time at within function scope, and rarely outside of function scope unless 
you have a clear purpose and well-documented call of a library of your own 
creation.

> it is a traceback from open() and sometimes play_fli() (in allegro). In
> play_fli() it can crash on open() but also on free(temp_bitmap). Is
> there a way to remove the free() commands in open()? My program is
> really large if that has anything to do with the crashes.

If open() or any system call is failing, it can mean you are having a 
serious problem with managing your resources, which may be the case here.  
Probably you could post some code, but it may be more useful just to point 
out the fundamentals, and then have you look over your code to make sure 
you are applying them.

There may be a bug in the allegro library if it is crashing on a free() 
call as well.  It would be a good idea to post the symified traceback to 
see just where the exception is happening.

> /Peter



Mitch Halloran
Research (Bio)chemist
Duzen Laboratories Group
Ankara       TURKEY

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019