Skip to content

Commit

Permalink
builtin/checkout.c: don't leak memory in check_tracking_name
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jeff King <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
drafnel authored and gitster committed Jun 18, 2013
1 parent 77eb44b commit 2c48420
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,16 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
memset(&query, 0, sizeof(struct refspec));
query.src = cb->src_ref;
if (remote_find_tracking(remote, &query) ||
get_sha1(query.dst, cb->dst_sha1))
get_sha1(query.dst, cb->dst_sha1)) {
free(query.dst);
return 0;
}
if (cb->dst_ref) {
free(query.dst);
cb->unique = 0;
return 0;
}
cb->dst_ref = xstrdup(query.dst);
cb->dst_ref = query.dst;
return 0;
}

Expand Down

0 comments on commit 2c48420

Please sign in to comment.