1
0
mirror of https://github.com/git/git synced 2024-07-02 15:48:44 +00:00

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>
This commit is contained in:
René Scharfe 2010-12-25 13:38:46 +01:00 committed by Junio C Hamano
parent abf411e28d
commit 5fd898141c

View File

@ -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;