Mail Archives: djgpp/1999/10/28/12:04:45
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 -