[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Small bug in libnetfs



On Wed, Dec 20, 2000 at 03:05:49AM +0100, Marcus Brinkmann wrote:
> On Tue, Dec 19, 2000 at 06:32:16PM -0500, Igor Khavkine wrote:
> > I came across a potential segfault in the libnetfs code.
> 
> Ah, yup. And that's not the only one of this type. You also find this in
> make-peropen.c has the same, and libdiskfs/file-chg.c, too.
> 
> A complete list would be helpful. To do this, one should grep for malloc
> and realloc and proofread every occurence. Sometimes ENOMEM should be
> returned, but NULL is correct here of course.
> 
> I am not checking this in right now, as we should do them all at once, so we
> don't forget about it.
> 
> Thanks,
> Marcus

Sounds like a plan. Here's a patch for every uncheck useage of malloc,
realloc and calloc, plus a few other minor things. Sometimes on error
we return a NULL, ENOMEM, exit or just place an assert (), trying
to keep consistency with the rest of the code and do something that
make sense. Still in a few places I wasn't sure how errors should be
reported (look for XXX's in my patch).

Now I understand why Hurd becomes unstable when it runs out of memory
and swap. That's because the code ALMOST NEVER checks the return of
malloc! And there's more still, strdup's and any other function which
returns malloced data.

Igor

P.S.: My request to anyone who contributes to the Hurd is, ALWAYS
check the return value of the malloc family of functions!

Attachment: malloc.diff.gz
Description: Binary data


Reply to: