summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-12-27 11:16:24 -0800
committerJunio C Hamano <gitster@pobox.com>2017-12-27 11:16:24 -0800
commita13e45f1e7e6fc02d4e10e0589578a77e84f3ffb (patch)
treeb05ce2f10a916bc9b60b5eb438b0db8f0e2238ad /strbuf.c
parent1f9ce78df08120f6a67107ccbc6b1c4658cd1808 (diff)
parentc3ff8f6c145638afe996b51e91375fd94cd064d0 (diff)
downloadgit-a13e45f1e7e6fc02d4e10e0589578a77e84f3ffb.tar.gz
Merge branch 'rs/strbuf-read-once-reset-length'
Leakfix. * rs/strbuf-read-once-reset-length: strbuf: release memory on read error in strbuf_read_once()
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index 323c49ceb3..ac5a7ab62d 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -386,12 +386,15 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
{
+ size_t oldalloc = sb->alloc;
ssize_t cnt;
strbuf_grow(sb, hint ? hint : 8192);
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
if (cnt > 0)
strbuf_setlen(sb, sb->len + cnt);
+ else if (oldalloc == 0)
+ strbuf_release(sb);
return cnt;
}