streaming: free git_istream upon closing

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>

Jeff King committed Jul 22, 2011 at 11:00 UTC 95dea6eb507109f64ab80f7fa2f73c39a0d14e7c
1 file changed +3 -1
streaming.c
+3 -1
@@ -94,7 +94,9 @@ struct git_istream {
94
95 int close_istream(struct git_istream *st)
96 {
97 - return st->vtbl->close(st);
97 + int r = st->vtbl->close(st);
98 + free(st);
99 + return r;
100 }
101
102 ssize_t read_istream(struct git_istream *st, char *buf, size_t sz)