summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
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 323c49c..ac5a7ab 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;
}