pgsql: Work around unportable behavior of malloc(0) and realloc(NULL, 0

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Work around unportable behavior of malloc(0) and realloc(NULL, 0
Date: 2012-10-02 21:32:58
Message-ID: E1TJA5K-0001r4-6N@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Work around unportable behavior of malloc(0) and realloc(NULL, 0).

On some platforms these functions return NULL, rather than the more common
practice of returning a pointer to a zero-sized block of memory. Hack our
various wrapper functions to hide the difference by substituting a size
request of 1. This is probably not so important for the callers, who
should never touch the block anyway if they asked for size 0 --- but it's
important for the wrapper functions themselves, which mistakenly treated
the NULL result as an out-of-memory failure. This broke at least pg_dump
for the case of no user-defined aggregates, as per report from
Matthew Carrington.

Back-patch to 9.2 to fix the pg_dump issue. Given the lack of previous
complaints, it seems likely that there is no live bug in previous releases,
even though some of these functions were in place before that.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/09ac603c36d1c865df68e5abd9dab04bd0fa5e48

Modified Files
--------------
contrib/oid2name/oid2name.c | 38 +++++++++++++++++++++++++----------
contrib/pg_upgrade/util.c | 24 ++++++++++++++--------
contrib/pgbench/pgbench.c | 6 +++++
src/backend/utils/misc/guc.c | 6 +++++
src/bin/initdb/initdb.c | 3 ++
src/bin/pg_basebackup/streamutil.c | 3 ++
src/bin/pg_ctl/pg_ctl.c | 3 ++
src/bin/pg_dump/dumpmem.c | 6 +++++
src/bin/psql/common.c | 3 ++
src/bin/scripts/common.c | 3 ++
src/port/dirmod.c | 12 +++++++++-
11 files changed, 85 insertions(+), 22 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2012-10-03 01:18:49 pgsql: In pg_upgrade, use full path name for analyze_new_cluster.sh scr
Previous Message Alvaro Herrera 2012-10-02 21:20:33 pgsql: Refactor "ALTER some-obj SET SCHEMA" implementation