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

Commit3aa3ae8

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 parentd5bea1f commit3aa3ae8

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
@@ -1303,15 +1303,15 @@ readMessageFromPipe(int fd)
13031303
{
13041304
/* could be any number */
13051305
bufsize+=16;
1306-
msg= (char*)realloc(msg,bufsize);
1306+
msg= (char*)pg_realloc(msg,bufsize);
13071307
}
13081308
}
13091309

13101310
/*
13111311
* Worker has closed the connection, make sure to clean up before return
13121312
* since we are not returning msg (but did allocate it).
13131313
*/
1314-
free(msg);
1314+
pg_free(msg);
13151315

13161316
returnNULL;
13171317
}

‎src/bin/psql/command.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,12 +1130,7 @@ exec_command(const char *cmd,
11301130
while ((opt=psql_scan_slash_option(scan_state,
11311131
OT_NORMAL,NULL, false)))
11321132
{
1133-
newval=realloc(newval,strlen(newval)+strlen(opt)+1);
1134-
if (!newval)
1135-
{
1136-
psql_error("out of memory\n");
1137-
exit(EXIT_FAILURE);
1138-
}
1133+
newval=pg_realloc(newval,strlen(newval)+strlen(opt)+1);
11391134
strcat(newval,opt);
11401135
free(opt);
11411136
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,13 +3975,8 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
39753975
if (nvars >=maxvars)
39763976
{
39773977
maxvars *=2;
3978-
varnames= (char**)realloc(varnames,
3979-
(maxvars+1)*sizeof(char*));
3980-
if (!varnames)
3981-
{
3982-
psql_error("out of memory\n");
3983-
exit(EXIT_FAILURE);
3984-
}
3978+
varnames= (char**)pg_realloc(varnames,
3979+
(maxvars+1)*sizeof(char*));
39853980
}
39863981

39873982
varnames[nvars++]=psprintf("%s%s%s",prefix,ptr->name,suffix);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp