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

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: (view raw or whole 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.



Modified Files
contrib/oid2name/oid2name.c        |   80 +++++++++++++++++++++--------------
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/psql/print.c               |    3 +
src/port/dirmod.c                  |   12 ++++-
11 files changed, 106 insertions(+), 43 deletions(-)

pgsql-committers by date

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

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