Skip site navigation (1) Skip section navigation (2)

pg_malloc() versus malloc(0)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: pg_malloc() versus malloc(0)
Date: 2012-10-01 14:00:46
Message-ID: 23126.1349100046@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: 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


Responses

pgsql-hackers by date

Next:From: Karl O. PincDate: 2012-10-01 14:05:32
Subject: Re: Doc patch, further describe and-mask nature of the permission system v2
Previous:From: Misa SimicDate: 2012-10-01 13:52:21
Subject: Re: is JSON really "a type" (Re: data to json enhancements)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group