Re: Missing checks when malloc returns NULL...

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Missing checks when malloc returns NULL...
Дата
Msg-id 25632.1472564132@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Missing checks when malloc returns NULL...  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers
Michael Paquier <michael.paquier@gmail.com> writes:
> On Tue, Aug 30, 2016 at 10:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I think what we ought to do is make ShmemAlloc act like palloc
>> (ie throw error not return NULL), and remove the duplicated error
>> checks.

> The only reason why I did not propose that for ShmemAlloc is because
> of extensions potentially using this routine and having some special
> handling when it returns NULL. And changing it to behave like palloc
> would break such extensions.

The evidence from the callers in core suggests that this change
would be much more likely to fix extensions than break them,
ie it's more likely that they are missing error checks than that
they have something useful to do if the alloc fails.

An extension that actually does need that could do something like

#if CATALOG_VERSION_NO < whatever-v10-is
#define ShmemAllocNoError(x) ShmemAlloc(x)
#endif

...
ptr = ShmemAllocNoError(size);if (ptr == NULL)  // same as before from here on

        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: standalone backend PANICs during recovery
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Missing checks when malloc returns NULL...