Avoid resource leak (src/bin/pg_resetwal/pg_resetwal.c)
Started by Ranier Vilela3 months ago2 messages
Hi.
Per Coverity.
The function *read_controlfile* is responsible for updating old pg_control
versions.
Coverity complains that the struct ControlFileData buffer is leaked.
I think that is right.
Trivial patch attached.
best regards,
Ranier Vilela
Attachments:
avoid-resource-leak-pg_resetwal.patchapplication/octet-stream; name=avoid-resource-leak-pg_resetwal.patchDownload
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index a89d72fc5c..ca8eaf86ad 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -613,6 +613,8 @@ read_controlfile(void)
memcpy(&ControlFile, buffer, sizeof(ControlFile));
+ pg_free(buffer);
+
/* return false if WAL segment size is not valid */
if (!IsValidWalSegSize(ControlFile.xlog_seg_size))
{
@@ -625,6 +627,7 @@ read_controlfile(void)
return true;
}
+ pg_free(buffer);
/* Looks like it's a mess. */
pg_log_warning("pg_control exists but is broken or wrong version; ignoring it");
Re: Avoid resource leak (src/bin/pg_resetwal/pg_resetwal.c)
On Thu, Oct 23, 2025 at 09:26:24PM -0300, Ranier Vilela wrote:
The function *read_controlfile* is responsible for updating old pg_control
versions.
Coverity complains that the struct ControlFileData buffer is leaked.I think that is right.
Bis repetita. Allocation in the context of a short-term binary
execution.
--
Michael