[Gllug] My and my malloc() problems....
Nix
nix at esperi.demon.co.uk
Wed Dec 26 22:29:17 UTC 2001
On 26 Dec 2001, Alex Hudson moaned:
> On Wed, 2001-12-26 at 00:39, Darran D. Rimron-Molloy wrote:
>> First of all, the machine IS NOT running out of ram, and the malloc itself
>> isn't failing.
>
> You seem awful sure the machine isn't running out of memory (ram !=
> memory) - how do you know? Linux overcommits, so if malloc were failing
> you would be _seriously_ worried.
It is very unlikely that the machine running out of memory would cause
malloc() to fail. It's far more likely that it would be signalled by a
memory access somewhere else sending your process a SIGSEGV (or SIGBUS?)
The only circumstance in which malloc() would fail due to resource
shortage that I can think of is if the machine ran out of, not RAM, but
*address space*, so malloc()'s internal mmap() failed --- and if you're
not allocating gigabytes in a single process, that's
unlikely. (Theoretically, it could also fail if you asked for a block
which couldn't be allocated without allocating more bytes than a size_t
could hold --- a *tad* unlikely.)
But malloc() can fail or kill the process if the heap management
structures get corrupted, which is fairly easy to do.
>> fails when I remove a sleep(1) statement from elsewhere in my code,
>
> The only way I can think that this might make a difference is if you're
> running threaded/event-driven code - the sleeps could be preventing some
> memoery error.
I doubt that's the problem. Your heap may be corrupted, but if that's
the case, I'm not sure how removing a sleep() could affect it; sleep()
doesn't call malloc() (in glibc-2.2.4, at least).
Try sticking a call to mcheck() just before the crash site; try running
with _MALLOC_CHECK=2 and seeing if the program aborts, or with
_MALLOC_CHECK=1 and seeing if anything strange gets printed to stderr
before the crash.
If neither of those do anything, it's *probably* not a heap corruption
problem, and it's time to look somewhere else.
> However, you're not providing any base case which fails (always debug an
> error to the smallest area of code possible), nor even saying how it
> fails.
Agreed, test cases are good :)
> BTW, Happy Boxing Day everyone :o)
Oh yes, indeed, (Turkey soup. Mmmmm.)
--
`Mmm... Maybe I just like strong women that can hurt me?'
--- Vadik, on female throat-cutting doctors
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list