@matheusbsbs / matheus-bagliano / commits / 5fd898141c
Fork 0

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 25, 2010 at 13:38 UTC 5fd898141ce2a243abf75192c9a55cb0a4e1ba80
1 file changed +3 -1
xdiff-interface.c
+3 -1
@@ -211,8 +211,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
211 return error("Could not open %s", filename);
212 sz = xsize_t(st.st_size);
213 ptr->ptr = xmalloc(sz ? sz : 1);
214 - if (sz && fread(ptr->ptr, sz, 1, f) != 1)
214 + if (sz && fread(ptr->ptr, sz, 1, f) != 1) {
215 + fclose(f);
216 return error("Could not read %s", filename);
217 + }
218 fclose(f);
219 ptr->size = sz;
220 return 0;