path: root/streaming.c
diff options
authorJohn Keeping <>2015-03-31 01:22:11 (GMT)
committerJunio C Hamano <>2015-03-31 19:14:42 (GMT)
commit9ce4ad3e0eac33b4cae38ebd76c26ddba2468631 (patch)
tree2cdf4771051cd839933373ac9088842d8f4bd1ea /streaming.c
parent47a02ff2ca821c52268197dd5fa46cd60a2e94bc (diff)
streaming.c: fix a memleak
When stream_blob_to_fd() opens an input stream with a filter, the filter gets discarded upon calling close_istream() before the function returns in the normal case. However, when we fail to open the stream, we failed to discard the filter. By discarding the filter in the failure case, give a consistent life-time rule of the filter to the callers; otherwise the callers need to conditionally discard the filter themselves, and this function does not give enough hint for the caller to do so correctly. Signed-off-by: John Keeping <> Signed-off-by: Stefan Beller <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'streaming.c')
1 files changed, 4 insertions, 1 deletions
diff --git a/streaming.c b/streaming.c
index 7e7ee2b..c4d421d 100644
--- a/streaming.c
+++ b/streaming.c
@@ -505,8 +505,11 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f
int result = -1;
st = open_istream(sha1, &type, &sz, filter);
- if (!st)
+ if (!st) {
+ if (filter)
+ free_stream_filter(filter);
return result;
+ }
if (type != OBJ_BLOB)
goto close_and_exit;
for (;;) {