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

[PATCH] close file on error in read_mmfile()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Dec 25, 2010, 12:38 UTC
Message-ID
<4D15E5D6.2040800@lsrfire.ath.cx>
Reported in http://qa.debian.org/daca/cppcheck/sid/git_1.7.2.3-2.2.html.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 xdiff-interface.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index cd2285d..cd9fa33 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -212,8 +212,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
 		return error("Could not open %s", filename);
 	sz = xsize_t(st.st_size);
 	ptr->ptr = xmalloc(sz ? sz : 1);
-	if (sz && fread(ptr->ptr, sz, 1, f) != 1)
+	if (sz && fread(ptr->ptr, sz, 1, f) != 1) {
+		fclose(f);
 		return error("Could not read %s", filename);
+	}
 	fclose(f);
 	ptr->size = sz;
 	return 0;
-- 
1.7.3.4
Next: René Scharfe
Message 1 of 3 in “close file on error in read_mmfile()”
  1. close file on error in read_mmfile()René Scharfe, Dec 25, 2010
  2. René ScharfeDec 25, 2010
  3. Junio C HamanoDec 26, 2010

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.