Re: Why pfree(NULL) breaks execution?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Marios Vodas <mvodas(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Why pfree(NULL) breaks execution?
Date: 2011-03-04 15:21:04
Message-ID: 27715.1299252064@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com> writes:
> On 4 March 2011 14:50, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> I think that free(NULL) works on some platforms but not all. I don't
>> see what advantage we'd get out of making pfree(NULL) silently work,
>> and there's a clear disadvantage: it would remove a useful sanity
>> check.

> I don't feel particularly strongly about what pfree() should do one
> way or the other, but that isn't so; free(NULL) works on all
> platforms, and is required to by the standard.

For the last few years it's been pretty safe to assume that, but it did
not use to be so --- pre ISO C spec, some malloc libraries allowed
free(NULL) and some didn't.

In any case, this has been debated before and the project policy is
that having pfree(NULL) throw an error is a net benefit. The main case
where it's really useful to not throw an error is where malloc(0)
returns NULL rather than a valid pointer (and BTW, both of those
behaviors are allowed by spec). However, palloc(0) is guaranteed
to give you a valid pointer that you can pfree, so that argument
doesn't hold here.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-03-04 15:43:52 Re: Quick Extensions Question
Previous Message Simon Riggs 2011-03-04 15:18:38 Re: Sync Rep v19