DORMANTno replies

[PATCH 1/2] Don't leak file descriptors from unavailable pack files.

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:42:52
Subsystem: the rest · Maintainer: Linus Torvalds

If open_packed_git failed it may have been because the packfile
actually exists and is readable, but some sort of verification
did not pass.  In this case open_packed_git left pack_fd filled
in, as the file descriptor is valid.  We don't want to leak the
file descriptor, nor do we want to allow someone in the future
to use this packed_git.

Signed-off-by: Shawn O. Pearce <redacted>
---
 sha1_file.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 37669d6..ba1c799 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1414,6 +1414,10 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
 			 * was loaded!
 			 */
 			if (p->pack_fd == -1 && open_packed_git(p)) {
+				if (p->pack_fd != -1) {
+					close(p->pack_fd);
+					p->pack_fd = -1;
+				}
 				error("packfile %s cannot be accessed", p->pack_name);
 				continue;
 			}
-- 
1.5.0.rc3.1.ge4b0e
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help