unpack_trees: plug leakage of o->result
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Nov 2014 20:12:41 +0000 (12:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Nov 2014 21:34:07 +0000 (13:34 -0800)
Most of the time the caller specifies to which destination variable
the resulting index_state should be assigned by passing a non-NULL
pointer in o->dst_index to receive that state, but for a caller that
gives a NULL o->dst_index, the resulting index simply leaked.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
unpack-trees.c
index ad3e9a04fe8ccb9286b94480f4484b0569f70a57..2515be6a608a517c84ec5df4c1fbeccbe9090b0b 100644 (file)
@@ -1157,6 +1157,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        if (o->dst_index) {
                discard_index(o->dst_index);
                *o->dst_index = o->result;
+       } else {
+               discard_index(&o->result);
        }
 
 done: