]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sys-utils: (save_adjtime): fix memory leak
authorMaks Mishin <maks.mishinFZ@gmail.com>
Thu, 17 Oct 2024 04:14:26 +0000 (07:14 +0300)
committerMaks Mishin <maks.mishinFZ@gmail.com>
Thu, 17 Oct 2024 04:14:47 +0000 (07:14 +0300)
Dynamic memory, referenced by 'content', is allocated by calling function 'xasprintf'
and lost when function returns.

Found by the static analyzer Svace.

sys-utils/hwclock.c

index cea249ebb10d66a8e2ae432d442ddf12da023c8f..9e3a957a7567ebb8ec57db53785d65cb7ec0eafb 100644 (file)
@@ -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;
 }