Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b13e5c

Browse files
committed
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, Coveritycomplains about it, so fix by using pg_realloc() instead.While looking for other instances, I noticed a couple of places inpsql that hadn't gotten the memo about the availability of pg_realloc.These aren't bugs, since they did have error checks, but verboselyinconsistent code is not a good thing.Back-patch as far as 9.3. 9.2 did not have pg_dump/parallel.c, nordid it have pg_realloc available in all frontend code.
1 parent606c012 commit8b13e5c

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

‎src/bin/pg_dump/parallel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,15 @@ readMessageFromPipe(int fd)
13081308
{
13091309
/* could be any number */
13101310
bufsize+=16;
1311-
msg= (char*)realloc(msg,bufsize);
1311+
msg= (char*)pg_realloc(msg,bufsize);
13121312
}
13131313
}
13141314

13151315
/*
13161316
* Worker has closed the connection, make sure to clean up before return
13171317
* since we are not returning msg (but did allocate it).
13181318
*/
1319-
free(msg);
1319+
pg_free(msg);
13201320

13211321
returnNULL;
13221322
}

‎src/bin/psql/command.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,7 @@ exec_command(const char *cmd,
11331133
while ((opt=psql_scan_slash_option(scan_state,
11341134
OT_NORMAL,NULL, false)))
11351135
{
1136-
newval=realloc(newval,strlen(newval)+strlen(opt)+1);
1137-
if (!newval)
1138-
{
1139-
psql_error("out of memory\n");
1140-
exit(EXIT_FAILURE);
1141-
}
1136+
newval=pg_realloc(newval,strlen(newval)+strlen(opt)+1);
11421137
strcat(newval,opt);
11431138
free(opt);
11441139
}

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,13 +4331,8 @@ append_variable_names(char ***varnames, int *nvars,
43314331
if (*nvars >=*maxvars)
43324332
{
43334333
*maxvars *=2;
4334-
*varnames= (char**)realloc(*varnames,
4335-
((*maxvars)+1)*sizeof(char*));
4336-
if (!(*varnames))
4337-
{
4338-
psql_error("out of memory\n");
4339-
exit(EXIT_FAILURE);
4340-
}
4334+
*varnames= (char**)pg_realloc(*varnames,
4335+
((*maxvars)+1)*sizeof(char*));
43414336
}
43424337

43434338
(*varnames)[(*nvars)++]=psprintf("%s%s%s",prefix,varname,suffix);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp