1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Fix memory leaks in archivePushFile().

The errorList is only used when throwing an error and the joined list is not needed after the error is thrown, so put both in the temp mem context.
This commit is contained in:
David Steele 2022-04-25 12:59:46 -04:00
parent 774db65086
commit 40ef64f2be

View File

@ -116,10 +116,11 @@ archivePushFile(
ASSERT(lstSize(repoList) > 0);
ArchivePushFileResult result = {.warnList = strLstNew()};
StringList *errorList = strLstDup(priorErrorList);
MEM_CONTEXT_TEMP_BEGIN()
{
StringList *const errorList = strLstDup(priorErrorList);
// Is this a WAL segment?
bool isSegment = walIsSegment(archiveFile);
@ -322,13 +323,13 @@ archivePushFile(
}
}
}
// Throw any errors, even if some pushes were successful. It is important that PostgreSQL receives an error so it does not
// remove the file.
if (strLstSize(errorList) > 0)
THROW_FMT(CommandError, CFGCMD_ARCHIVE_PUSH " command encountered error(s):\n%s", strZ(strLstJoin(errorList, "\n")));
}
MEM_CONTEXT_TEMP_END();
// Throw any errors, even if some pushes were successful. It is important that PostgreSQL receives an error so it does not
// remove the file.
if (strLstSize(errorList) > 0)
THROW_FMT(CommandError, CFGCMD_ARCHIVE_PUSH " command encountered error(s):\n%s", strZ(strLstJoin(errorList, "\n")));
FUNCTION_LOG_RETURN_STRUCT(result);
}