[PATCH] git-local-fetch: Avoid calling close(-1)
authorSergey Vlasov <vsu@altlinux.ru>
Fri, 23 Sep 2005 12:28:28 +0000 (16:28 +0400)
committerJunio C Hamano <junkio@cox.net>
Fri, 23 Sep 2005 21:30:45 +0000 (14:30 -0700)
After open() failure, copy_file() called close(ifd) with ifd == -1
(harmless, but causes Valgrind noise).  The same thing was possible
for the destination file descriptor.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
Signed-off-by: Junio C Hamano <junkio@cox.net>
local-fetch.c

index b3947a9..a3e35f9 100644 (file)
@@ -75,7 +75,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
                void *map;
                ifd = open(source, O_RDONLY);
                if (ifd < 0 || fstat(ifd, &st) < 0) {
-                       close(ifd);
+                       if (ifd >= 0)
+                               close(ifd);
                        fprintf(stderr, "cannot open %s\n", source);
                        return -1;
                }
@@ -89,7 +90,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
                status = ((ofd < 0) ||
                          (write(ofd, map, st.st_size) != st.st_size));
                munmap(map, st.st_size);
-               close(ofd);
+               if (ofd >= 0)
+                       close(ofd);
                if (status)
                        fprintf(stderr, "cannot write %s\n", dest);
                else