summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b6cab3)
raw | patch | inline | side by side (parent: 6b6cab3)
author | Jeff King <peff@peff.net> | |
Fri, 22 Jul 2011 17:00:03 +0000 (11:00 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 22 Jul 2011 21:30:49 +0000 (14:30 -0700) |
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>
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>
streaming.c | patch | blob | history |
diff --git a/streaming.c b/streaming.c
index 91414f459231a83e6d22ee5a91bd0f6bc65ff5b0..d8c16d28f6c5ee56fcdc03f2db1b4f0630df3c5d 100644 (file)
--- a/streaming.c
+++ b/streaming.c
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)