Skip to content

Commit 1a95181

Browse files
sigprofJunio C Hamano
authored andcommitted
[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>
1 parent 8be707d commit 1a95181

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

local-fetch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
7575
void *map;
7676
ifd = open(source, O_RDONLY);
7777
if (ifd < 0 || fstat(ifd, &st) < 0) {
78-
close(ifd);
78+
if (ifd >= 0)
79+
close(ifd);
7980
fprintf(stderr, "cannot open %s\n", source);
8081
return -1;
8182
}
@@ -89,7 +90,8 @@ static int copy_file(const char *source, const char *dest, const char *hex)
8990
status = ((ofd < 0) ||
9091
(write(ofd, map, st.st_size) != st.st_size));
9192
munmap(map, st.st_size);
92-
close(ofd);
93+
if (ofd >= 0)
94+
close(ofd);
9395
if (status)
9496
fprintf(stderr, "cannot write %s\n", dest);
9597
else

0 commit comments

Comments
 (0)