[PATCH 4/6] git-local-fetch: Avoid calling close(-1)

From: Sergey Vlasov <vsu@altlinux.ru>
Date: 2005-09-23 22:28:28
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>


---

 local-fetch.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

bb38750b6016dcd8dc71b2cd0a3bdef035f6508d
diff --git a/local-fetch.c b/local-fetch.c
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -75,7 +75,8 @@ static int copy_file(const char *source,
 		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,
 		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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Fri Sep 23 22:28:55 2005

This archive was generated by hypermail 2.1.8 : 2005-09-23 22:30:58 EST