Re: unchecked malloc

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: unchecked malloc
Дата
Msg-id 7684.1127797405@sss.pgh.pa.us
обсуждение исходный текст
Ответ на unchecked malloc  ("Qingqing Zhou" <zhouqq@cs.toronto.edu>)
Список 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 по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: State of support for back PG branches
Следующее
От: "Qingqing Zhou"
Дата:
Сообщение: Re: unchecked malloc