Re: unchecked malloc - Mailing list pgsql-hackers

From Tom Lane
Subject Re: unchecked malloc
Date
Msg-id 7684.1127797405@sss.pgh.pa.us
Whole thread Raw
In response to unchecked malloc  ("Qingqing Zhou" <zhouqq@cs.toronto.edu>)
List pgsql-hackers
"Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> There are several places in both backend and tools that forget to check the 
> return value of malloc(). For example(8.0.1),

>     backend/port/dynloader/beos.c/pg_dlopen()
Dead port, probably not worth fixing.

>     backend/bootstrap/bootstrap.c/AddStr()
This code will never be run under memory pressure, so althoughit theoretically should be fixed, I'm having a hard time
gettingexcitedabout it.  In any case palloc would be the correct fix.
 

>     port/strdup.c/strdup()
Definitely broken; I just fixed it to conform to the
SUShttp://www.opengroup.org/onlinepubs/007908799/xsh/strdup.html(ofcourse, this code isn't used on any remotely
modernplatform,so it's probably not very relevant...)
 
>     bin/pg_dump/common.c/findParentsByOid()
Probably should be fixed, although if pg_dump runs out of memoryit's just gonna fail anyway.

> To report the "out of memory" error, we should differenciate if
> ErrorContext is already set up.

No, because you're thinking in terms of the backend environment, and
generally in the backend the answer to "when to use malloc directly"
is "never".  The client-side tools are the only place where this is
a serious question, and offhand I'd say "gripe to stderr and exit(1)"
is going to be the right answer in all cases there.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: State of support for back PG branches
Next
From: "Qingqing Zhou"
Date:
Subject: Re: unchecked malloc