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

Commit8485a25

Browse files
committed
Fix assorted infelicities in new SetWALSegSize() function.
* Failure to check for malloc failure (ok, pretty unlikely here, butthat's not an excuse).* Leakage of open fd on read error, and of malloc'd buffer always.* Incorrect assumption that a short read would set errno to zero.* Failure to adhere to message style conventions (in particular,not reporting errno where relevant; using "couldn't open" rather than"could not open" is not really in line with project style either).* Missing newlines on some messages.Coverity spotted the leak problems; I noticed the rest whilefixing the leaks.
1 parent6dda099 commit8485a25

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

‎contrib/pg_standby/pg_standby.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,21 @@ SetWALSegSize(void)
408408
{
409409
boolret_val= false;
410410
intfd;
411-
char*buf= (char*)malloc(XLOG_BLCKSZ);
411+
412+
/* malloc this buffer to ensure sufficient alignment: */
413+
char*buf= (char*)pg_malloc(XLOG_BLCKSZ);
412414

413415
Assert(WalSegSz==-1);
414416

415417
if ((fd=open(WALFilePath,O_RDWR,0))<0)
416418
{
417-
fprintf(stderr,"%s: couldn't open WAL file \"%s\"\n",
418-
progname,WALFilePath);
419+
fprintf(stderr,"%s: could not open WAL file \"%s\": %s\n",
420+
progname,WALFilePath,strerror(errno));
421+
pg_free(buf);
419422
return false;
420423
}
424+
425+
errno=0;
421426
if (read(fd,buf,XLOG_BLCKSZ)==XLOG_BLCKSZ)
422427
{
423428
XLogLongPageHeaderlonghdr= (XLogLongPageHeader)buf;
@@ -433,7 +438,6 @@ SetWALSegSize(void)
433438
fprintf(stderr,
434439
"%s: WAL segment size must be a power of two between 1MB and 1GB, but the WAL file header specifies %d bytes\n",
435440
progname,WalSegSz);
436-
close(fd);
437441
}
438442
else
439443
{
@@ -444,17 +448,21 @@ SetWALSegSize(void)
444448
if (errno!=0)
445449
{
446450
if (debug)
447-
fprintf(stderr,"could not read file \"%s\": %s",
451+
fprintf(stderr,"could not read file \"%s\": %s\n",
448452
WALFilePath,strerror(errno));
449453
}
450454
else
451455
{
452456
if (debug)
453-
fprintf(stderr,"not enough data in file \"%s\"",WALFilePath);
457+
fprintf(stderr,"not enough data in file \"%s\"\n",
458+
WALFilePath);
454459
}
455460
}
456461

457462
fflush(stderr);
463+
464+
close(fd);
465+
pg_free(buf);
458466
returnret_val;
459467
}
460468

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp