From: Maks Mishin Date: Thu, 17 Oct 2024 04:14:26 +0000 (+0300) Subject: sys-utils: (save_adjtime): fix memory leak X-Git-Tag: v2.42-start~176^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e4fd6a5fc84b8dc172e1ea67b28064c67376d1a;p=thirdparty%2Futil-linux.git 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. --- diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index cea249ebb..9e3a957a7 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; }