git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 606c012)
Fix some bogus direct uses of realloc().
2014年11月18日 18:28:06 +0000 (13:28 -0500)
2014年11月18日 18:28:06 +0000 (13:28 -0500)
pg_dump/parallel.c was using realloc() directly with no error check.
While the odds of an actual failure here seem pretty low, Coverity
complains about it, so fix by using pg_realloc() instead.

While looking for other instances, I noticed a couple of places in
psql that hadn't gotten the memo about the availability of pg_realloc.
These aren't bugs, since they did have error checks, but verbosely
inconsistent code is not a good thing.

Back-patch as far as 9.3. 9.2 did not have pg_dump/parallel.c, nor
did it have pg_realloc available in all frontend code.


diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index 29d20130a9671b2c170cbe043fc24d8cdf5350f8..0a9ac0287a986313e34b7d2a58b00ccfa30edf33 100644 (file)
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -1308,7 +1308,7 @@ readMessageFromPipe(int fd)
{
/* could be any number */
bufsize += 16;
- msg = (char *) realloc(msg, bufsize);
+ msg = (char *) pg_realloc(msg, bufsize);
}
}
@@ -1316,7 +1316,7 @@ readMessageFromPipe(int fd)
* Worker has closed the connection, make sure to clean up before return
* since we are not returning msg (but did allocate it).
*/
- free(msg);
+ pg_free(msg);
return NULL;
}
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 260893523a5bde71e1bbeea926586708a8e17ec2..3a884028b54d8f8f0760c429419468c1445ba991 100644 (file)
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1133,12 +1133,7 @@ exec_command(const char *cmd,
while ((opt = psql_scan_slash_option(scan_state,
OT_NORMAL, NULL, false)))
{
- newval = realloc(newval, strlen(newval) + strlen(opt) + 1);
- if (!newval)
- {
- psql_error("out of memory\n");
- exit(EXIT_FAILURE);
- }
+ newval = pg_realloc(newval, strlen(newval) + strlen(opt) + 1);
strcat(newval, opt);
free(opt);
}
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 8c85425fc5df32812573c1cff33e8cf15f51cdfd..278d3952d4d0ad6e2c2d6707d96a715f9505fb44 100644 (file)
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -4331,13 +4331,8 @@ append_variable_names(char ***varnames, int *nvars,
if (*nvars >= *maxvars)
{
*maxvars *= 2;
- *varnames = (char **) realloc(*varnames,
- ((*maxvars) + 1) * sizeof(char *));
- if (!(*varnames))
- {
- psql_error("out of memory\n");
- exit(EXIT_FAILURE);
- }
+ *varnames = (char **) pg_realloc(*varnames,
+ ((*maxvars) + 1) * sizeof(char *));
}
(*varnames)[(*nvars)++] = psprintf("%s%s%s", prefix, varname, suffix);
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /