util-linux/backport-sys-utils-save_adjtime-fix-memory-leak.patch

43 lines
1.2 KiB
Diff
Raw Permalink Normal View History

From 4e4fd6a5fc84b8dc172e1ea67b28064c67376d1a Mon Sep 17 00:00:00 2001
From: Maks Mishin <maks.mishinFZ@gmail.com>
Date: Thu, 17 Oct 2024 07:14:26 +0300
Subject: [PATCH] sys-utils: (save_adjtime): fix memory leak
Dynamic memory, referenced by 'content', is allocated by calling function 'xasprintf'
and lost when function returns.
Found by the static analyzer Svace.
Reference:https://github.com/util-linux/util-linux/commit/4e4fd6a5fc84b8dc172e1ea67b28064c67376d1a
Conflict:NA
---
sys-utils/hwclock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index cea249eb..9e3a957a 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -917,6 +917,7 @@ static int save_adjtime(const struct hwclock_control *ctl,
fp = fopen(ctl->adj_file_name, "w");
if (fp == NULL) {
warn(_("cannot open %s"), ctl->adj_file_name);
+ free(content);
return EXIT_FAILURE;
}
@@ -925,9 +926,11 @@ static int save_adjtime(const struct hwclock_control *ctl,
if (rc) {
warn(_("cannot update %s"), ctl->adj_file_name);
+ free(content);
return EXIT_FAILURE;
}
}
+ free(content);
return EXIT_SUCCESS;
}
--
2.33.0