diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-02 17:31:40 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-02 17:32:42 -0400 |
commit | 09ac603c36d1c865df68e5abd9dab04bd0fa5e48 (patch) | |
tree | adc4fb1c6d6c2bf116bf539d18fd3aba0a4e0312 /src/bin/scripts/common.c | |
parent | 2164f9a1254980a02ef9ca99ee3bcb8c1298b219 (diff) | |
download | postgresql-09ac603c36d1c865df68e5abd9dab04bd0fa5e48.tar.gz postgresql-09ac603c36d1c865df68e5abd9dab04bd0fa5e48.zip |
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.
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r-- | src/bin/scripts/common.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index 4a7d02f7771..7d8875d81cd 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -304,6 +304,9 @@ pg_malloc(size_t size) { void *tmp; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; tmp = malloc(size); if (!tmp) { |