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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Mar 10, 2015 at 16:51 UTC
c8a571d8bcef7f5687b5eb86654805c39f236e5d
1 file changed
+5
-6
bundle.c
+5
-6
@@ -334,7 +334,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
334
if (e->item->flags & UNINTERESTING)
335
continue;
336
if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
337
- continue;
337
+ goto skip_write_ref;
338
if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag))
339
flag = 0;
340
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
@@ -342,7 +342,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
342
if (e->item->type == OBJ_TAG &&
343
!is_tag_in_date_range(e->item, revs)) {
344
e->item->flags |= UNINTERESTING;
345
- continue;
345
+ goto skip_write_ref;
346
}
347
348
/*
@@ -357,8 +357,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
357
if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
358
warning(_("ref '%s' is excluded by the rev-list options"),
359
e->name);
360
- free(ref);
361
- continue;
360
+ goto skip_write_ref;
361
}
362
/*
363
* If you run "git bundle create bndl v1.0..v2.0", the
@@ -388,8 +387,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
387
obj->flags |= SHOWN;
388
add_pending_object(revs, obj, e->name);
389
}
391
- free(ref);
392
- continue;
390
+ goto skip_write_ref;
391
}
392
393
ref_count++;
@@ -397,6 +395,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
395
write_or_die(bundle_fd, " ", 1);
396
write_or_die(bundle_fd, display_ref, strlen(display_ref));
397
write_or_die(bundle_fd, "\n", 1);
398
+ skip_write_ref:
399
free(ref);
400
}
401