[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>
This commit is contained in:
parent
8be707de55
commit
1a951815dd
@ -75,6 +75,7 @@ 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) {
|
||||
if (ifd >= 0)
|
||||
close(ifd);
|
||||
fprintf(stderr, "cannot open %s\n", source);
|
||||
return -1;
|
||||
@ -89,6 +90,7 @@ 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);
|
||||
if (ofd >= 0)
|
||||
close(ofd);
|
||||
if (status)
|
||||
fprintf(stderr, "cannot write %s\n", dest);
|
||||
|
Loading…
Reference in New Issue
Block a user