diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-04-25 10:32:13 +0200 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-04-25 10:32:13 +0200 |
commit | 0bd56172b2871e94c0d7115ffbf430308317ac49 (patch) | |
tree | aaf886bec977d52b8191a0a284437f7667a6556f /src/backend/commands/dbcommands.c | |
parent | f819020d400f1dbd96ee1a9fd44a1f6f44932b4d (diff) | |
download | postgresql-0bd56172b2871e94c0d7115ffbf430308317ac49.tar.gz postgresql-0bd56172b2871e94c0d7115ffbf430308317ac49.zip |
Always pfree strings returned by GetDatabasePath
Several places didn't do it, and in many cases it didn't matter because
it would be a small allocation in a short-lived context; but other
places may accumulate a few (for example, in CreateDatabaseUsingFileCopy,
one per tablespace). In most databases this is highly unlikely to be
very serious either, but it seems better to make the code consistent in
case there's future copy-and-paste.
The only case of actual concern seems to be the aforementioned routine,
which is new with commit 9c08aea6a309, so there's no need to backpatch.
As pointed out by Coverity.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r-- | src/backend/commands/dbcommands.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 1bbecfeddf6..9d0f83cde31 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -217,6 +217,8 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid, UnlockRelationId(&dstrelid, AccessShareLock); } + pfree(srcpath); + pfree(dstpath); list_free_deep(rnodelist); } @@ -628,6 +630,8 @@ CreateDatabaseUsingFileCopy(Oid src_dboid, Oid dst_dboid, Oid src_tsid, (void) XLogInsert(RM_DBASE_ID, XLOG_DBASE_CREATE_FILE_COPY | XLR_SPECIAL_REL_UPDATE); } + pfree(srcpath); + pfree(dstpath); } table_endscan(scan); table_close(rel, AccessShareLock); @@ -2128,6 +2132,9 @@ movedb(const char *dbname, const char *tblspcname) /* Now it's safe to release the database lock */ UnlockSharedObjectForSession(DatabaseRelationId, db_id, 0, AccessExclusiveLock); + + pfree(src_dbpath); + pfree(dst_dbpath); } /* Error cleanup callback for movedb */ @@ -2141,6 +2148,8 @@ movedb_failure_callback(int code, Datum arg) dstpath = GetDatabasePath(fparms->dest_dboid, fparms->dest_tsoid); (void) rmtree(dstpath, true); + + pfree(dstpath); } /* @@ -3051,6 +3060,9 @@ dbase_redo(XLogReaderState *record) * We don't need to copy subdirectories */ copydir(src_path, dst_path, false); + + pfree(src_path); + pfree(dst_path); } else if (info == XLOG_DBASE_CREATE_WAL_LOG) { @@ -3063,6 +3075,7 @@ dbase_redo(XLogReaderState *record) /* Create the database directory with the version file. */ CreateDirAndVersionFile(dbpath, xlrec->db_id, xlrec->tablespace_id, true); + pfree(dbpath); } else if (info == XLOG_DBASE_DROP) { |