streaming.c: fix a memleak
authorJohn Keeping <john@keeping.me.uk>
Tue, 31 Mar 2015 01:22:11 +0000 (18:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Mar 2015 19:14:42 +0000 (12:14 -0700)
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 <john@keeping.me.uk>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
streaming.c
index 7e7ee2be6fe147ff660f8ab25618fbe4d4d0f11c..c4d421d5990b03c9b510d4f8ae4e4a25c414a275 100644 (file)
@@ -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 (;;) {