From: René Scharfe Date: Sat, 25 Dec 2010 12:38:46 +0000 (+0100) Subject: close file on error in read_mmfile() X-Git-Tag: v1.7.4-rc0~1^2~7^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5fd898141ce2a243abf75192c9a55cb0a4e1ba80;p=git.git 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 --- 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;