Re: Safe memory allocation functions

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Safe memory allocation functions
Date: 2015-01-16 14:56:37
Message-ID: CA+TgmoYzyP9gw5+ME5Mcr+k7fX_XCgcxpkVM+Y=zf=WXcm9ewA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 15, 2015 at 10:57 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
>> Hmm, I understood Tom to be opposing the idea of a palloc variant that
>> returns NULL on failure, and I understand you to be supporting it.
>> But maybe I'm confused.
>
> Your understanding seems correct to me. I was just saying that your
> description of Tom's argument to dislike the idea seemed at odds with
> what he was actually saying.

OK, that may be. I'm not sure.

>> Anyway, I support it. I agree that there are
>> systems (or circumstances?) where malloc is going to succeed and then
>> the world will blow up later on anyway, but I don't think that means
>> that an out-of-memory error is the only sensible response to a palloc
>> failure; returning NULL seems like a sometimes-useful alternative.
>>
>> I do think that "safe" is the wrong suffix. Maybe palloc_soft_fail()
>> or palloc_null() or palloc_no_oom() or palloc_unsafe().
>
> I liked palloc_noerror() better myself FWIW.

I don't care for noerror() because it probably still will error in
some circumstances; just not for OOM.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2015-01-16 15:09:25 Re: Safe memory allocation functions
Previous Message Merlin Moncure 2015-01-16 14:38:56 Re: hung backends stuck in spinlock heavy endless loop