Skip to content

Commit a13e45f

Browse files
committed
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()
2 parents 1f9ce78 + c3ff8f6 commit a13e45f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

strbuf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,15 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
386386

387387
ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
388388
{
389+
size_t oldalloc = sb->alloc;
389390
ssize_t cnt;
390391

391392
strbuf_grow(sb, hint ? hint : 8192);
392393
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
393394
if (cnt > 0)
394395
strbuf_setlen(sb, sb->len + cnt);
396+
else if (oldalloc == 0)
397+
strbuf_release(sb);
395398
return cnt;
396399
}
397400

0 commit comments

Comments
 (0)