pg_malloc() versus malloc(0) - Mailing list pgsql-hackers

From Tom Lane
Subject pg_malloc() versus malloc(0)
Date
Msg-id 23126.1349100046@sss.pgh.pa.us
Whole thread Raw
Responses Re: pg_malloc() versus malloc(0)  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
Re: pg_malloc() versus malloc(0)  (Peter Geoghegan <peter@2ndquadrant.com>)
List pgsql-hackers
Per
http://archives.postgresql.org/pgsql-general/2012-10/msg00013.php
we have got a problem with the pg_malloc() interface functions that
were recently added to pg_dump and a lot of other frontend code.
Namely, that on platforms where malloc(0) returns NULL instead of
a pointer to a zero-size block, pg_malloc thinks it's a failure
and aborts the program.

There are basically two ways we could fix this:

1. Teach pg_malloc not to complain if result == NULL and size == 0.

2. Before the malloc call, have it replace size == 0 with size = 1.

#2 would guarantee no NULL returns from pg_malloc, which would be closer
to the behavior of palloc in the backend.  On the other hand, it seems
a bit wasteful and inelegant.  Any code that was capable of calling
malloc(0) before is presumably not going to be upset by a NULL return,
or we'd have seen trouble reports sooner.

Any opinions which way to go?  I'm not convinced either way yet.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Misa Simic
Date:
Subject: Re: is JSON really "a type" (Re: data to json enhancements)
Next
From: "Karl O. Pinc"
Date:
Subject: Re: Doc patch, further describe and-mask nature of the permission system v2