OSDN Git Service

sequencer.c: check return value of close() in rewrite_file()
authorSimon Ruderich <simon@ruderich.org>
Wed, 1 Nov 2017 14:45:42 +0000 (15:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Nov 2017 04:39:13 +0000 (13:39 +0900)
Not checking close(2) can hide errors as not all errors are reported
during the write(2).

Signed-off-by: Simon Ruderich <simon@ruderich.org>
Reviewed-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c

index f93b60f..e0cc2f7 100644 (file)
@@ -2673,7 +2673,8 @@ static int rewrite_file(const char *path, const char *buf, size_t len)
                return error_errno(_("could not open '%s' for writing"), path);
        if (write_in_full(fd, buf, len) < 0)
                rc = error_errno(_("could not write to '%s'"), path);
-       close(fd);
+       if (close(fd) && !rc)
+               rc = error_errno(_("could not close '%s'"), path);
        return rc;
 }