On Mon, May 04, 1998 at 05:46:59PM -0400, Alex Heiphetz wrote:
> I'm having a weird problem with free() behaviour under Linux.
> The program compiles fine, but in runtime it
> *sometimes* dumps core which, thanks to gdb, can be
> traced to free() calls. This is especially true when calls
> to free() repeat, i.e. within the loop. Second free() is
> guaranteed to dump core while first does it sometimes.
> On BSDI and freeBSD same program runs perfectly every time.
Problems like this are essentially ALWAYS due to a bug in the program.
likely causes:
-the pointer you're passing to free is not a value that
was returned from the allocator (malloc, calloc, realloc).
This could be because it has been trashed by a memory overwrite
somewhere else, or it has been modified by pointer arithmetic,
or you're just passing the wrong value.
-Most malloc implementations build a chain of allocated blocks
with some "bookkeeping" information interspersed between the
allocated blocks. If your program writes one byte beyond the end
of a block, or one byte before its start, you've just damaged
the bookeeping data. Next time you call one of the alloction
routines, or next time you try to free() one of the blocks, if
the allocator/free needs to travese the damaged region it'll
take a detour off into the weeds: core dump time!
Some implementations are more forgiving and some aren't. Personally, I
like the sort that core dump at the slightest such error cause they help
to debug the program for me!
I think its most likely a bug in your program. You don't very often find
a bug of this nature in a system library (though it's not impossible!).
Fred
--
---- Fred Smith -- [EMAIL PROTECTED] ----------------------------
The Lord detests the way of the wicked
but he loves those who pursue righteousness.
----------------------------- Proverbs 15:9 (niv) -----------------------------
--
PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject.