submodule: submodule_move_head omits old argument in forced case
[gitweb.git] / strbuf.c
index 29169b8ef8b75a6638b5594501b95dee3e1f4b4b..8007be8fbafdc3f4542e27cfc9344044f71d43dc 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -408,12 +408,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;
 }