Skip to content

Commit

Permalink
bundle.c: fix memory leak
Browse files Browse the repository at this point in the history
There was one continue statement without an accompanying `free(ref)`.
Instead of adding that, replace all the free&&continue with a goto
just after writing the refs, where we'd do the free anyway and then
reloop.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Stefan Beller authored and Junio C Hamano committed Mar 11, 2015
1 parent 04f20c0 commit c8a571d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
if (e->item->flags & UNINTERESTING)
continue;
if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
continue;
goto skip_write_ref;
if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag))
flag = 0;
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;

if (e->item->type == OBJ_TAG &&
!is_tag_in_date_range(e->item, revs)) {
e->item->flags |= UNINTERESTING;
continue;
goto skip_write_ref;
}

/*
Expand All @@ -357,8 +357,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
warning(_("ref '%s' is excluded by the rev-list options"),
e->name);
free(ref);
continue;
goto skip_write_ref;
}
/*
* If you run "git bundle create bndl v1.0..v2.0", the
Expand Down Expand Up @@ -388,15 +387,15 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
obj->flags |= SHOWN;
add_pending_object(revs, obj, e->name);
}
free(ref);
continue;
goto skip_write_ref;
}

ref_count++;
write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
write_or_die(bundle_fd, " ", 1);
write_or_die(bundle_fd, display_ref, strlen(display_ref));
write_or_die(bundle_fd, "\n", 1);
skip_write_ref:
free(ref);
}

Expand Down

0 comments on commit c8a571d

Please sign in to comment.