From 5fd898141ce2a243abf75192c9a55cb0a4e1ba80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 25 Dec 2010 13:38:46 +0100 Subject: [PATCH] close file on error in read_mmfile() Reported in http://qa.debian.org/daca/cppcheck/sid/git_1.7.2.3-2.2.html and in http://thread.gmane.org/gmane.comp.version-control.git/123042. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- xdiff-interface.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xdiff-interface.c b/xdiff-interface.c index 01f14fb50..b78f75719 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -211,8 +211,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; -- 2.30.2