diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-04-23 22:07:56 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-23 22:07:56 -0700 |
commit | f9096db54b29ed17afc6e3393f159ea55142b14c (patch) | |
tree | 250cf5594f21f55a19c00b16559a9c3a221013b0 /refs | |
parent | a507115e29690e831fedb060cfb50cef9e0f7514 (diff) | |
parent | fa1912c89a72fbd94591f4f5d522e5867ffe9bb6 (diff) | |
download | git-f9096db54b29ed17afc6e3393f159ea55142b14c.tar.gz |
Merge branch 'rs/misc-cppcheck-fixes'
Various small fixes.
* rs/misc-cppcheck-fixes:
server-info: avoid calling fclose(3) twice in update_info_file()
files_for_each_reflog_ent_reverse(): close stream and free strbuf on error
am: close stream on error, but not stdin
Diffstat (limited to 'refs')
-rw-r--r-- | refs/files-backend.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index 4d705b4037..c9d900fd12 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3294,8 +3294,8 @@ 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", - refname, strerror(errno)); + ret = error("cannot seek back reflog for %s: %s", + refname, strerror(errno)); pos = ftell(logfp); while (!ret && 0 < pos) { int cnt; @@ -3305,13 +3305,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", - refname, strerror(errno)); + 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", - cnt, refname, strerror(errno)); + 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; |