Re: Missing checks when malloc returns NULL... - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Missing checks when malloc returns NULL...
Date
Msg-id 25632.1472564132@sss.pgh.pa.us
Whole thread Raw
In response to Re: Missing checks when malloc returns NULL...  (Michael Paquier <michael.paquier@gmail.com>)
List 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 by date:

Previous
From: Michael Paquier
Date:
Subject: Re: standalone backend PANICs during recovery
Next
From: Tom Lane
Date:
Subject: Re: Missing checks when malloc returns NULL...