threads / patch / 26136

patchclose file on error in read_mmfile()

Subject: [PATCH] close file on error in read_mmfile()

## tl;dr

3 messages between Dec 25, 2010 and Dec 26, 2010. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

René Scharfe· Dec 25, 2010, 12:38 UTC · lore
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(-)
Show changes to xdiff-interface.c +3 −1
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
René Scharfe· Dec 25, 2010, 12:44 UTC · re: René Scharfe · lore

Re: [PATCH] close file on error in read_mmfile()

Am 25.12.2010 13:38, schrieb René Scharfe:
> Reported in http://qa.debian.org/daca/cppcheck/sid/git_1.7.2.3-2.2.html.
Oh, and also in http://thread.gmane.org/gmane.comp.version-control.git/123042.
René

← back to recent threads