From: Karel Zak Date: Fri, 11 Jun 2021 13:17:42 +0000 (+0200) Subject: hwclock: close adjtime on write error [coverity scan] X-Git-Tag: v2.38-rc1~463 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fdb178370d7dbff6637fbfe63a1a7043904c3f5;p=thirdparty%2Futil-linux.git hwclock: close adjtime on write error [coverity scan] Signed-off-by: Karel Zak --- diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 6b4e8ce5b0..e9102e33a7 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -901,13 +901,18 @@ static int save_adjtime(const struct hwclock_control *ctl, } if (!ctl->testing) { + int rc; + fp = fopen(ctl->adj_file_name, "w"); if (fp == NULL) { warn(_("cannot open %s"), ctl->adj_file_name); return EXIT_FAILURE; } - if (fputs(content, fp) < 0 || close_stream(fp) != 0) { + rc = fputs(content, fp) < 0; + rc += close_stream(fp); + + if (rc) { warn(_("cannot update %s"), ctl->adj_file_name); return EXIT_FAILURE; }