Skip to content

Commit

Permalink
[PATCH] git-local-fetch: Avoid calling close(-1)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sigprof authored and Junio C Hamano committed Sep 23, 2005
1 parent 8be707d commit 1a95181
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions local-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit 1a95181

Please sign in to comment.