git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 2, 2007, 08:00 UTC
Message-ID
<20070202080003.GA21094@spearce.org>

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>
---
 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
Next: Junio C Hamano
Message 1 of 4 in “Don't leak file descriptors from unavailable pack files.”
  1. 1/2 Don't leak file descriptors from unavailable pack files.Shawn O. Pearce, Feb 2, 2007
  2. Junio C HamanoFeb 2, 2007
  3. Shawn O. PearceFeb 2, 2007
  4. Junio C HamanoFeb 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.