Skip to content

Commit

Permalink
close file on error in read_mmfile()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Dec 26, 2010
1 parent abf411e commit 5fd8981
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion xdiff-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5fd8981

Please sign in to comment.