Skip to content

Commit

Permalink
streaming: free git_istream upon closing
Browse files Browse the repository at this point in the history
Kirill Smelkov noticed that post-1.7.6 "git checkout"
started leaking tons of memory. The streaming_write_entry
function properly calls close_istream(), but that function
did not actually free() the allocated git_istream struct.

The git_istream struct is totally opaque to calling code,
and must be heap-allocated by open_istream. Therefore it's
not appropriate for callers to have to free it.

This patch makes close_istream() into "close and de-allocate
all associated resources". We could add a new "free_istream"
call, but there's not much point in letting callers inspect
the istream after close. And this patch's semantics make us
match fopen/fclose, which is well-known and understood.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jul 22, 2011
1 parent 6b6cab3 commit 95dea6e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ struct git_istream {

int close_istream(struct git_istream *st)
{
return st->vtbl->close(st);
int r = st->vtbl->close(st);
free(st);
return r;
}

ssize_t read_istream(struct git_istream *st, char *buf, size_t sz)
Expand Down

0 comments on commit 95dea6e

Please sign in to comment.