Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
Merge branch 'rs/strbuf-read-once-reset-length'
author
Junio C Hamano
<gitster@pobox.com>
Wed, 27 Dec 2017 19:16:24 +0000
(11:16 -0800)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 27 Dec 2017 19:16:24 +0000
(11:16 -0800)
Leakfix.
* rs/strbuf-read-once-reset-length:
strbuf: release memory on read error in strbuf_read_once()
strbuf.c
patch
|
blob
|
history
raw
(from parent 1:
1f9ce78
)
diff --git
a/strbuf.c
b/strbuf.c
index 323c49ceb35cb053434248df869578e649ccadc0..ac5a7ab62d554fb292d29df9cb618a336c5336c0 100644
(file)
--- 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;
}