mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-07-19 12:01:18 +02:00
Fix some bogus direct uses of realloc().
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.
This commit is contained in:
parent
d5bea1fbcc
commit
3aa3ae8e1d
@ -1303,7 +1303,7 @@ readMessageFromPipe(int fd)
|
|||||||
{
|
{
|
||||||
/* could be any number */
|
/* could be any number */
|
||||||
bufsize += 16;
|
bufsize += 16;
|
||||||
msg = (char *) realloc(msg, bufsize);
|
msg = (char *) pg_realloc(msg, bufsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1311,7 +1311,7 @@ readMessageFromPipe(int fd)
|
|||||||
* Worker has closed the connection, make sure to clean up before return
|
* Worker has closed the connection, make sure to clean up before return
|
||||||
* since we are not returning msg (but did allocate it).
|
* since we are not returning msg (but did allocate it).
|
||||||
*/
|
*/
|
||||||
free(msg);
|
pg_free(msg);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1130,12 +1130,7 @@ exec_command(const char *cmd,
|
|||||||
while ((opt = psql_scan_slash_option(scan_state,
|
while ((opt = psql_scan_slash_option(scan_state,
|
||||||
OT_NORMAL, NULL, false)))
|
OT_NORMAL, NULL, false)))
|
||||||
{
|
{
|
||||||
newval = realloc(newval, strlen(newval) + strlen(opt) + 1);
|
newval = pg_realloc(newval, strlen(newval) + strlen(opt) + 1);
|
||||||
if (!newval)
|
|
||||||
{
|
|
||||||
psql_error("out of memory\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
strcat(newval, opt);
|
strcat(newval, opt);
|
||||||
free(opt);
|
free(opt);
|
||||||
}
|
}
|
||||||
|
@ -3975,13 +3975,8 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
|
|||||||
if (nvars >= maxvars)
|
if (nvars >= maxvars)
|
||||||
{
|
{
|
||||||
maxvars *= 2;
|
maxvars *= 2;
|
||||||
varnames = (char **) realloc(varnames,
|
varnames = (char **) pg_realloc(varnames,
|
||||||
(maxvars + 1) * sizeof(char *));
|
(maxvars + 1) * sizeof(char *));
|
||||||
if (!varnames)
|
|
||||||
{
|
|
||||||
psql_error("out of memory\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix);
|
varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix);
|
||||||
|
Loading…
Reference in New Issue
Block a user