This is an automated email from the ASF dual-hosted git repository. yjhjstz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 8cd506cead8bd940aea3a4d738d1cec1cd3b245e Author: Alvaro Herrera <[email protected]> AuthorDate: Mon Apr 25 10:32:13 2022 +0200 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. fix free --- src/backend/commands/dbcommands.c | 10 ++++++++++ src/backend/utils/init/postinit.c | 1 + 2 files changed, 11 insertions(+) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index d1146d3d4e..fe368b28d3 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -767,6 +767,9 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt) (void) XLogInsert(RM_DBASE_ID, XLOG_DBASE_CREATE | XLR_SPECIAL_REL_UPDATE); } + + pfree(srcpath); + pfree(dstpath); } SIMPLE_FAULT_INJECTOR("after_xlog_create_database"); @@ -1591,6 +1594,8 @@ movedb(const char *dbname, const char *tblspcname) */ ScheduleDbDirDelete(db_id, src_tblspcoid, true); + pfree(src_dbpath); + pfree(dst_dbpath); SIMPLE_FAULT_INJECTOR("inside_move_db_transaction"); } @@ -1609,6 +1614,8 @@ movedb_failure_callback(int code, Datum arg) dstpath = GetDatabasePath(fparms->dest_dboid, fparms->dest_tsoid); (void) rmtree(dstpath, true); + + pfree(dstpath); } #endif @@ -2501,6 +2508,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_DROP) { diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 42678d254a..bf36404ecf 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -1166,6 +1166,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, } SetDatabasePath(fullpath); + pfree(fullpath); /* * It's now possible to do real access to the system catalogs. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
