[PATCH] git-local-fetch: Avoid calling close(-1)
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>
Sergey Vlasov committed
Sep 23, 2005 at 16:28 UTC
1a951815ddaa4e4b570cc67e204f45e9a12841e0
1 file changed
+4
-2
local-fetch.c
+4
-2
@@ -75,7 +75,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
75
void *map;
76
ifd = open(source, O_RDONLY);
77
if (ifd < 0 || fstat(ifd, &st) < 0) {
78
- close(ifd);
78
+ if (ifd >= 0)
79
+ close(ifd);
80
fprintf(stderr, "cannot open %s\n", source);
81
return -1;
82
}
@@ -89,7 +90,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
90
status = ((ofd < 0) ||
91
(write(ofd, map, st.st_size) != st.st_size));
92
munmap(map, st.st_size);
92
- close(ofd);
93
+ if (ofd >= 0)
94
+ close(ofd);
95
if (status)
96
fprintf(stderr, "cannot write %s\n", dest);
97
else