mirror of
https://github.com/git/git.git
synced 2024-11-24 18:33:43 +08:00
files_for_each_reflog_ent_reverse(): close stream and free strbuf on error
Exit the loop orderly through the cleanup code, instead of dashing out with logfp still open and sb leaking. Found with Cppcheck. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ac8ce18d89
commit
be686f03e0
@ -3169,7 +3169,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
|
||||
|
||||
/* Jump to the end */
|
||||
if (fseek(logfp, 0, SEEK_END) < 0)
|
||||
return error("cannot seek back reflog for %s: %s",
|
||||
ret = error("cannot seek back reflog for %s: %s",
|
||||
refname, strerror(errno));
|
||||
pos = ftell(logfp);
|
||||
while (!ret && 0 < pos) {
|
||||
@ -3180,13 +3180,17 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
|
||||
|
||||
/* Fill next block from the end */
|
||||
cnt = (sizeof(buf) < pos) ? sizeof(buf) : pos;
|
||||
if (fseek(logfp, pos - cnt, SEEK_SET))
|
||||
return error("cannot seek back reflog for %s: %s",
|
||||
if (fseek(logfp, pos - cnt, SEEK_SET)) {
|
||||
ret = error("cannot seek back reflog for %s: %s",
|
||||
refname, strerror(errno));
|
||||
break;
|
||||
}
|
||||
nread = fread(buf, cnt, 1, logfp);
|
||||
if (nread != 1)
|
||||
return error("cannot read %d bytes from reflog for %s: %s",
|
||||
if (nread != 1) {
|
||||
ret = error("cannot read %d bytes from reflog for %s: %s",
|
||||
cnt, refname, strerror(errno));
|
||||
break;
|
||||
}
|
||||
pos -= cnt;
|
||||
|
||||
scanp = endp = buf + cnt;
|
||||
|
Loading…
Reference in New Issue
Block a user