hwclock: close adjtime on write error [coverity scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-11 15:17:42 +02:00
parent 777fe9f512
commit 3fdb178370
1 changed files with 6 additions and 1 deletions

View File

@ -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;
}