Skip to content

Commit

Permalink
get_expanded_map(): avoid memory leak
Browse files Browse the repository at this point in the history
The old code could leak *expn_name if match_name_with_pattern()
succeeded but ignore_symref_update() returned true.  So make sure that
*expn_name is freed in any case.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Oct 30, 2013
1 parent f166db2 commit e31a17f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,9 +1567,9 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
struct ref *ret = NULL;
struct ref **tail = &ret;

char *expn_name;

for (ref = remote_refs; ref; ref = ref->next) {
char *expn_name = NULL;

if (strchr(ref->name, '^'))
continue; /* a dereference item */
if (match_name_with_pattern(refspec->src, ref->name,
Expand All @@ -1578,12 +1578,12 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
struct ref *cpy = copy_ref(ref);

cpy->peer_ref = alloc_ref(expn_name);
free(expn_name);
if (refspec->force)
cpy->peer_ref->force = 1;
*tail = cpy;
tail = &cpy->next;
}
free(expn_name);
}

return ret;
Expand Down

0 comments on commit e31a17f

Please sign in to comment.