Bus error DURING call to malloc()

Dan Watts dwatts at ki.UUCP
Tue Jun 12 23:21:50 AEST 1990


In article <1990Jun10.211156.16153 at calgary.uucp> paquette at cpsc.ucalgary.ca (Trevor Paquette) writes:
>In article <14525 at thorin.cs.unc.edu>, taylorr at glycine.cs.unc.edu (Russell Taylor) writes:
>> 
>> 	We are running OS 3.2.2 on an IRIS 4D/240GTX.  I ran a program and
>> got the proverbial 'Bus error (core dumped)' message.  The catch is that
>> when I run dbx and look for the error, it tells me that the error occured
>> IN malloc():
> < stuff deleted >
>   Note: this does not 'fix' the problem.. you are now using a different
>     malloc.

My experience has been that this error is caused by a program writing
outside the bounds of a malloc'd area.  This causes the hidden memory
management headers to get corrupted.  A quick hack would be to add some
constant pad to all malloc's.  Try adding 128 bytes and see if that does
it. Since my mistakes are usually in writing one byte too much, a pad
of 16 works ok.  Note that this hasn't solved the code problem, it's just
defensive programming.  You might also not failures in printf() due to
the same reason.  I usually track this down by putting in calls to malloc()
in other places in the code and try to find the _bad_ code by seeing which
ones work, and which ones die (note to free() the malloc()'d mem just
after getting it).
-- 
#####################################################################
# CompuServe: >INTERNET:uunet.UU.NET!ki!dwatts    Dan Watts         #
# UUCP      : ...!uunet!ki!dwatts                 Ki Research, Inc. #
############### New Dimensions In Network Connectivity ##############



More information about the Comp.sys.sgi mailing list