From bc325a65d10ed6b136272fe64a67a042b81ae838 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Oct 2024 10:22:08 +0200 Subject: [PATCH] hwclock: cleanup save_adjtime() Signed-off-by: Karel Zak --- sys-utils/hwclock.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 9e3a957a7..2b33dfbce 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -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; } /* -- 2.47.3