Skip to content

Commit c8a571d

Browse files
stefanbellergitster
authored andcommitted
bundle.c: fix memory leak
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04f20c0 commit c8a571d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

bundle.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,15 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
334334
if (e->item->flags & UNINTERESTING)
335335
continue;
336336
if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
337-
continue;
337+
goto skip_write_ref;
338338
if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag))
339339
flag = 0;
340340
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
341341

342342
if (e->item->type == OBJ_TAG &&
343343
!is_tag_in_date_range(e->item, revs)) {
344344
e->item->flags |= UNINTERESTING;
345-
continue;
345+
goto skip_write_ref;
346346
}
347347

348348
/*
@@ -357,8 +357,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
357357
if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
358358
warning(_("ref '%s' is excluded by the rev-list options"),
359359
e->name);
360-
free(ref);
361-
continue;
360+
goto skip_write_ref;
362361
}
363362
/*
364363
* If you run "git bundle create bndl v1.0..v2.0", the
@@ -388,15 +387,15 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
388387
obj->flags |= SHOWN;
389388
add_pending_object(revs, obj, e->name);
390389
}
391-
free(ref);
392-
continue;
390+
goto skip_write_ref;
393391
}
394392

395393
ref_count++;
396394
write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
397395
write_or_die(bundle_fd, " ", 1);
398396
write_or_die(bundle_fd, display_ref, strlen(display_ref));
399397
write_or_die(bundle_fd, "\n", 1);
398+
skip_write_ref:
400399
free(ref);
401400
}
402401

0 commit comments

Comments
 (0)