Skip to content

Commit 5fd8981

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abf411e commit 5fd8981

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

xdiff-interface.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
211211
return error("Could not open %s", filename);
212212
sz = xsize_t(st.st_size);
213213
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);
215216
return error("Could not read %s", filename);
217+
}
216218
fclose(f);
217219
ptr->size = sz;
218220
return 0;

0 commit comments

Comments
 (0)