зеркало из https://github.com/microsoft/git.git
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()
This commit is contained in:
Коммит
a13e45f1e7
3
strbuf.c
3
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)
|
ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
|
||||||
{
|
{
|
||||||
|
size_t oldalloc = sb->alloc;
|
||||||
ssize_t cnt;
|
ssize_t cnt;
|
||||||
|
|
||||||
strbuf_grow(sb, hint ? hint : 8192);
|
strbuf_grow(sb, hint ? hint : 8192);
|
||||||
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
|
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
|
||||||
if (cnt > 0)
|
if (cnt > 0)
|
||||||
strbuf_setlen(sb, sb->len + cnt);
|
strbuf_setlen(sb, sb->len + cnt);
|
||||||
|
else if (oldalloc == 0)
|
||||||
|
strbuf_release(sb);
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче