afarah wrote:
Under what condition will we see a segmentation fault in the malloc
library routine? Specifically, a failure in call to "chunk_allo c()"
from within malloc.
I have a multi-threaded c++ program that occasionally core-dumps in
"malloc" when running on Linux 2.4 (it always works fine on Solaris
5). The stack trace shows the final call to "chunk_allo c".
I would like to re-create this bug within a debugger. However, the
segmentation fault happens so infrequently that I think I need to have
a better idea of how a problem like this can arise before I can
re-create it.
Many thanks in advance for any ideas.
Multi-threading is OT here simply because C++ program model is a single
process on a single CPU with all parts of the program executing in
a sequence. Intrinsics of C library are too, because they are very
compiler-specific. Differences between OSes are also beyond the scope
of this newsgroup. Perhaps you will find better help in a forum for
your compiler or OS. Try comp.os.linux.d evelopment.apps or gnu.g++.help.
In general a library routine fails when it gets invalid input, and there
is no invalid input for malloc, IIRC. Any number you pass in is going to
be interpreted as an unsigned integral value, and the system will either
allocate the requested amount, in which case a pointer to it is returned,
or fail to do so, in which case it will return a null pointer.
In most cases unexpected segmentation faults are due to memory corruption
that happened some time before the code that breaks is executed. You may
need some memory checking tools (like Purify) to see what's going wrong
with the program's memory. Of course, program's being multithreaded
doesn't really help...
Good luck!
Victor