summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vlasov <vsu@altlinux.ru>2005-09-23 12:28:28 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-09-23 21:30:45 (GMT)
commit1a951815ddaa4e4b570cc67e204f45e9a12841e0 (patch)
tree8a44a8e894c6239dd063dcaf841f63e6c35fc9cb
parent8be707de55e473a5d850a1fcdc6e30589a37d548 (diff)
downloadgit-1a951815ddaa4e4b570cc67e204f45e9a12841e0.zip
git-1a951815ddaa4e4b570cc67e204f45e9a12841e0.tar.gz
git-1a951815ddaa4e4b570cc67e204f45e9a12841e0.tar.bz2
[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>
-rw-r--r--local-fetch.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/local-fetch.c b/local-fetch.c
index b3947a9..a3e35f9 100644
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -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