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

Commit84e4570

Browse files
committed
Fix set of issues with memory-allocation system calls in frontend code
Like the backend, the frontend has wrappers on top of malloc() and suchwhose use is recommended. Particularly, it is possible to do memoryallocation without issuing an error. Some binaries missed the use ofthose wrappers, so let's fix the gap for consistency.This also fixes two latent bugs:- In pg_dump/pg_dumpall when parsing an ACL item, on an out-of-memoryerror for strdup(), the code considered the failure as a ACL parsingproblem instead of an actual OOM.- In pg_waldump, an OOM when building the target directory string wouldcause a crash.Author: Daniel GustafssonDiscussion:https://postgr.es/m/gY0y9xenfoBPc-Tufsr2Zg-MmkrJslm0Tw_CMg4p_j58-k_PXNC0klMdkKQkg61BkXC9_uWo-DcUzfxnHqpkpoR5jjVZrPHqKYikcHIiONhg=@yesql.se
1 parent34ff542 commit84e4570

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,8 @@ GetPrivilegesToDelete(HANDLE hToken)
19791979
returnNULL;
19801980
}
19811981

1982-
tokenPrivs= (PTOKEN_PRIVILEGES)malloc(length);
1982+
tokenPrivs= (PTOKEN_PRIVILEGES)pg_malloc_extended(length,
1983+
MCXT_ALLOC_NO_OOM);
19831984
if (tokenPrivs==NULL)
19841985
{
19851986
write_stderr(_("%s: out of memory\n"),progname);

‎src/bin/pg_dump/dumputils.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,13 @@ parseAclItem(const char *item, const char *type,
481481
char*slpos;
482482
char*pos;
483483

484-
buf=strdup(item);
485-
if (!buf)
486-
return false;
484+
buf=pg_strdup(item);
487485

488486
/* user or group name is string up to = */
489487
eqpos=copyAclUserName(grantee,buf);
490488
if (*eqpos!='=')
491489
{
492-
free(buf);
490+
pg_free(buf);
493491
return false;
494492
}
495493

@@ -501,13 +499,13 @@ parseAclItem(const char *item, const char *type,
501499
slpos=copyAclUserName(grantor,slpos);
502500
if (*slpos!='\0')
503501
{
504-
free(buf);
502+
pg_free(buf);
505503
return false;
506504
}
507505
}
508506
else
509507
{
510-
free(buf);
508+
pg_free(buf);
511509
return false;
512510
}
513511

@@ -617,7 +615,7 @@ do { \
617615
appendPQExpBuffer(privs,"(%s)",subname);
618616
}
619617

620-
free(buf);
618+
pg_free(buf);
621619

622620
return true;
623621
}

‎src/bin/pg_test_fsync/pg_test_fsync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ handle_args(int argc, char *argv[])
170170
switch (option)
171171
{
172172
case'f':
173-
filename=strdup(optarg);
173+
filename=pg_strdup(optarg);
174174
break;
175175

176176
case's':

‎src/bin/pg_waldump/pg_waldump.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
247247
{
248248
if (search_directory(directory,fname))
249249
{
250-
private->inpath=strdup(directory);
250+
private->inpath=pg_strdup(directory);
251251
return;
252252
}
253253

254254
/* directory / XLOGDIR */
255255
snprintf(fpath,MAXPGPATH,"%s/%s",directory,XLOGDIR);
256256
if (search_directory(fpath,fname))
257257
{
258-
private->inpath=strdup(fpath);
258+
private->inpath=pg_strdup(fpath);
259259
return;
260260
}
261261
}
@@ -266,13 +266,13 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
266266
/* current directory */
267267
if (search_directory(".",fname))
268268
{
269-
private->inpath=strdup(".");
269+
private->inpath=pg_strdup(".");
270270
return;
271271
}
272272
/* XLOGDIR */
273273
if (search_directory(XLOGDIR,fname))
274274
{
275-
private->inpath=strdup(XLOGDIR);
275+
private->inpath=pg_strdup(XLOGDIR);
276276
return;
277277
}
278278

@@ -283,7 +283,7 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
283283
snprintf(fpath,MAXPGPATH,"%s/%s",datadir,XLOGDIR);
284284
if (search_directory(fpath,fname))
285285
{
286-
private->inpath=strdup(fpath);
286+
private->inpath=pg_strdup(fpath);
287287
return;
288288
}
289289
}

‎src/bin/psql/large_obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
200200
char*bufptr;
201201
size_tslen=strlen(comment_arg);
202202

203-
cmdbuf=malloc(slen*2+256);
203+
cmdbuf=pg_malloc_extended(slen*2+256,MCXT_ALLOC_NO_OOM);
204204
if (!cmdbuf)
205205
returnfail_lo_xact("\\lo_import",own_transaction);
206206
sprintf(cmdbuf,"COMMENT ON LARGE OBJECT %u IS '",loid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp