]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: cleanup save_adjtime()
authorKarel Zak <kzak@redhat.com>
Tue, 22 Oct 2024 08:22:08 +0000 (10:22 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 22 Oct 2024 08:22:08 +0000 (10:22 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/hwclock.c

index 9e3a957a7567ebb8ec57db53785d65cb7ec0eafb..2b33dfbce55f1ae209624ca3b3595a27904e96b6 100644 (file)
@@ -898,6 +898,7 @@ static int save_adjtime(const struct hwclock_control *ctl,
 {
        char *content;          /* Stuff to write to disk file */
        FILE *fp;
+       int rc = EXIT_FAILURE;
 
        xasprintf(&content, "%f %"PRId64" %f\n%"PRId64"\n%s\n",
                  adjtime->drift_factor,
@@ -917,8 +918,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;
+                       goto done;
                }
 
                rc = fputs(content, fp) < 0;
@@ -926,12 +926,14 @@ static int save_adjtime(const struct hwclock_control *ctl,
 
                if (rc) {
                        warn(_("cannot update %s"), ctl->adj_file_name);
-                       free(content);
-                       return EXIT_FAILURE;
+                       goto done;
                }
        }
+
+       rc = EXIT_SUCCESS;
+done:
        free(content);
-       return EXIT_SUCCESS;
+       return rc;
 }
 
 /*