builtin/checkout.c: don't leak memory in check_tracking_name
remote_find_tracking() populates the query struct with an allocated string in the dst member. So, we do not need to xstrdup() the string, since we can transfer ownership from the query struct (which will go out of scope at the end of this function) to our callback struct, but we must free the string if it will not be used so we will not leak memory. Let's do so. Signed-off-by: Brandon Casey <drafnel@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Jun 17, 2013 at 18:40 UTC
2c4842023205b4b2cf7eac973cd7dc2fca263327
1 file changed
+5
-2
builtin/checkout.c
+5
-2
@@ -838,13 +838,16 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
838
memset(&query, 0, sizeof(struct refspec));
839
query.src = cb->src_ref;
840
if (remote_find_tracking(remote, &query) ||
841
- get_sha1(query.dst, cb->dst_sha1))
841
+ get_sha1(query.dst, cb->dst_sha1)) {
842
+ free(query.dst);
843
return 0;
844
+ }
845
if (cb->dst_ref) {
846
+ free(query.dst);
847
cb->unique = 0;
848
return 0;
849
}
847
- cb->dst_ref = xstrdup(query.dst);
850
+ cb->dst_ref = query.dst;
851
return 0;
852
}
853