summaryrefslogtreecommitdiff
path: root/contrib/pg_upgrade/util.c
diff options
context:
space:
mode:
authorTom Lane2012-07-18 05:13:20 +0000
committerTom Lane2012-07-18 05:13:20 +0000
commit3d6ec663bb701b7192822f83a6a1cf4f7574d67e (patch)
tree9b7444c0094bf31973e7c22909de51f10fee0ae8 /contrib/pg_upgrade/util.c
parent73b796a52c50d6f44400c99eff1a01c89d08782f (diff)
Improve pg_upgrade's load_directory() function.
Error out on out-of-memory, rather than returning -1, which the sole existing caller wasn't checking for anyway. There doesn't seem to be any use-case for making the caller check for failure here. Detect failure return from readdir(). Use a less platform-dependent method of calculating the entrysize. It's possible, but not yet confirmed, that this explains bug #6733, in which Mike Wilson reports a pg_upgrade crash that did not occur in 9.1. (Note that load_directory is effectively new code in 9.2, at least on platforms that have scandir().) Fix up comments, avoid uselessly using two counters, reduce the number of realloc calls to something sane.
Diffstat (limited to 'contrib/pg_upgrade/util.c')
-rw-r--r--contrib/pg_upgrade/util.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c
index 6977663b63a..76cd20b23d7 100644
--- a/contrib/pg_upgrade/util.c
+++ b/contrib/pg_upgrade/util.c
@@ -183,7 +183,7 @@ get_user_info(char **user_name)
void *
-pg_malloc(int n)
+pg_malloc(size_t n)
{
void *p = malloc(n);
@@ -193,6 +193,17 @@ pg_malloc(int n)
return p;
}
+void *
+pg_realloc(void *ptr, size_t n)
+{
+ void *p = realloc(ptr, n);
+
+ if (p == NULL)
+ pg_log(PG_FATAL, "%s: out of memory\n", os_info.progname);
+
+ return p;
+}
+
void
pg_free(void *p)