Skip to content

Commit d8480a7

Browse files
tglsfdcCommitfest Bot
authored andcommitted
Fix leaks in startup process.
These leaks are of absolutely no real-world consequence, since they are small one-time leaks in a one-time process. But this is the last step to get to zero reported leaks in a run of the core regression tests, so let's do it. Author: Tom Lane <[email protected]> Discussion: https://postgr.es/m/[email protected]
1 parent 1d32147 commit d8480a7

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/backend/access/transam/xlog.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static void InitControlFile(uint64 sysidentifier, uint32 data_checksum_version);
703703
static void WriteControlFile(void);
704704
static void ReadControlFile(void);
705705
static void UpdateControlFile(void);
706-
static char *str_time(pg_time_t tnow);
706+
static char *str_time(pg_time_t tnow, char *buf, size_t bufsize);
707707

708708
static int get_sync_bit(int method);
709709

@@ -5371,11 +5371,9 @@ BootStrapXLOG(uint32 data_checksum_version)
53715371
}
53725372

53735373
static char *
5374-
str_time(pg_time_t tnow)
5374+
str_time(pg_time_t tnow, char *buf, size_t bufsize)
53755375
{
5376-
char *buf = palloc(128);
5377-
5378-
pg_strftime(buf, 128,
5376+
pg_strftime(buf, bufsize,
53795377
"%Y-%m-%d %H:%M:%S %Z",
53805378
pg_localtime(&tnow, log_timezone));
53815379

@@ -5618,6 +5616,7 @@ StartupXLOG(void)
56185616
XLogRecPtr missingContrecPtr;
56195617
TransactionId oldestActiveXID;
56205618
bool promoted = false;
5619+
char timebuf[128];
56215620

56225621
/*
56235622
* We should have an aux process resource owner to use, and we should not
@@ -5646,41 +5645,47 @@ StartupXLOG(void)
56465645
*/
56475646
ereport(IsPostmasterEnvironment ? LOG : NOTICE,
56485647
(errmsg("database system was shut down at %s",
5649-
str_time(ControlFile->time))));
5648+
str_time(ControlFile->time,
5649+
timebuf, sizeof(timebuf)))));
56505650
break;
56515651

56525652
case DB_SHUTDOWNED_IN_RECOVERY:
56535653
ereport(LOG,
56545654
(errmsg("database system was shut down in recovery at %s",
5655-
str_time(ControlFile->time))));
5655+
str_time(ControlFile->time,
5656+
timebuf, sizeof(timebuf)))));
56565657
break;
56575658

56585659
case DB_SHUTDOWNING:
56595660
ereport(LOG,
56605661
(errmsg("database system shutdown was interrupted; last known up at %s",
5661-
str_time(ControlFile->time))));
5662+
str_time(ControlFile->time,
5663+
timebuf, sizeof(timebuf)))));
56625664
break;
56635665

56645666
case DB_IN_CRASH_RECOVERY:
56655667
ereport(LOG,
56665668
(errmsg("database system was interrupted while in recovery at %s",
5667-
str_time(ControlFile->time)),
5669+
str_time(ControlFile->time,
5670+
timebuf, sizeof(timebuf))),
56685671
errhint("This probably means that some data is corrupted and"
56695672
" you will have to use the last backup for recovery.")));
56705673
break;
56715674

56725675
case DB_IN_ARCHIVE_RECOVERY:
56735676
ereport(LOG,
56745677
(errmsg("database system was interrupted while in recovery at log time %s",
5675-
str_time(ControlFile->checkPointCopy.time)),
5678+
str_time(ControlFile->checkPointCopy.time,
5679+
timebuf, sizeof(timebuf))),
56765680
errhint("If this has occurred more than once some data might be corrupted"
56775681
" and you might need to choose an earlier recovery target.")));
56785682
break;
56795683

56805684
case DB_IN_PRODUCTION:
56815685
ereport(LOG,
56825686
(errmsg("database system was interrupted; last known up at %s",
5683-
str_time(ControlFile->time))));
5687+
str_time(ControlFile->time,
5688+
timebuf, sizeof(timebuf)))));
56845689
break;
56855690

56865691
default:
@@ -6325,6 +6330,12 @@ StartupXLOG(void)
63256330
*/
63266331
CompleteCommitTsInitialization();
63276332

6333+
/* Clean up EndOfWalRecoveryInfo data to appease Valgrind leak checking */
6334+
if (endOfRecoveryInfo->lastPage)
6335+
pfree(endOfRecoveryInfo->lastPage);
6336+
pfree(endOfRecoveryInfo->recoveryStopReason);
6337+
pfree(endOfRecoveryInfo);
6338+
63286339
/*
63296340
* All done with end-of-recovery actions.
63306341
*

src/backend/access/transam/xlogrecovery.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ ShutdownWalRecovery(void)
16261626
close(readFile);
16271627
readFile = -1;
16281628
}
1629+
pfree(xlogreader->private_data);
16291630
XLogReaderFree(xlogreader);
16301631
XLogPrefetcherFree(xlogprefetcher);
16311632

0 commit comments

Comments
 (0)