Anonymous avatar Anonymous committed 1a95181

[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>;

Comments (0)

Files changed (1)

 		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;
 		}
 		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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.