summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0d18e41)
raw | patch | inline | side by side (parent: 0d18e41)
author | Shawn O. Pearce <spearce@spearce.org> | |
Fri, 2 Feb 2007 08:00:03 +0000 (03:00 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 3 Feb 2007 05:33:18 +0000 (21:33 -0800) |
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 <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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 <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
sha1_file.c | patch | blob | history |
diff --git a/sha1_file.c b/sha1_file.c
index 2eff14ac87e3596194733086b94342a3112e2eee..45e410e8833024f471f9e2b3972963961de2bbba 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
}
}
-static int open_packed_git(struct packed_git *p)
+/*
+ * Do not call this directly as this leaks p->pack_fd on error return;
+ * call open_packed_git() instead.
+ */
+static int open_packed_git_1(struct packed_git *p)
{
struct stat st;
struct pack_header hdr;
return 0;
}
+static int open_packed_git(struct packed_git *p)
+{
+ if (!open_packed_git_1(p))
+ return 0;
+ if (p->pack_fd != -1) {
+ close(p->pack_fd);
+ p->pack_fd = -1;
+ }
+ return -1;
+}
+
static int in_window(struct pack_window *win, unsigned long offset)
{
/* We must promise at least 20 bytes (one hash) after the