Skip to content

Commit f6bfea0

Browse files
avargitster
authored andcommitted
revisions API users: use release_revisions() in builtin/log.c
In preparation for having the "log" family of functions make wider use of release_revisions() let's have them call it just before exiting. This changes the "log", "whatchanged", "show", "format-patch", etc. commands, all of which live in this file. The release_revisions() API still only frees the "pending" member, but will learn to release more members of "struct rev_info" in subsequent commits. In the case of "format-patch" revert the addition of UNLEAK() in dee839a (format-patch: mark rev_info with UNLEAK, 2021-12-16), which will cause several tests that previously passed under "TEST_PASSES_SANITIZE_LEAK=true" to start failing. In subsequent commits we'll now be able to use those tests to check whether that part of the API is really leaking memory, and will fix all of those memory leaks. Removing the UNLEAK() allows us to make incremental progress in that direction. See [1] for further details about this approach. Note that the release_revisions() will not be sufficient to deal with the code in cmd_show() added in 5d7eeee (git-show: grok blobs, trees and tags, too, 2006-12-14) which clobbers the "pending" array in the case of "OBJ_COMMIT". That will need to be dealt with by some future follow-up work. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b78ce33 commit f6bfea0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

builtin/log.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
295295
cmd_log_init_finish(argc, argv, prefix, rev, opt);
296296
}
297297

298+
static int cmd_log_deinit(int ret, struct rev_info *rev)
299+
{
300+
release_revisions(rev);
301+
return ret;
302+
}
303+
298304
/*
299305
* This gives a rough estimate for how many commits we
300306
* will print out in the list.
@@ -558,7 +564,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
558564
cmd_log_init(argc, argv, prefix, &rev, &opt);
559565
if (!rev.diffopt.output_format)
560566
rev.diffopt.output_format = DIFF_FORMAT_RAW;
561-
return cmd_log_walk(&rev);
567+
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
562568
}
563569

564570
static void show_tagger(const char *buf, struct rev_info *rev)
@@ -677,7 +683,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
677683
cmd_log_init(argc, argv, prefix, &rev, &opt);
678684

679685
if (!rev.no_walk)
680-
return cmd_log_walk(&rev);
686+
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
681687

682688
count = rev.pending.nr;
683689
objects = rev.pending.objects;
@@ -732,8 +738,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
732738
ret = error(_("unknown type: %d"), o->type);
733739
}
734740
}
735-
free(objects);
736-
return ret;
741+
return cmd_log_deinit(ret, &rev);
737742
}
738743

739744
/*
@@ -761,7 +766,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
761766
rev.always_show_header = 1;
762767
cmd_log_init_finish(argc, argv, prefix, &rev, &opt);
763768

764-
return cmd_log_walk(&rev);
769+
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
765770
}
766771

767772
static void log_setup_revisions_tweak(struct rev_info *rev,
@@ -792,7 +797,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
792797
opt.revarg_opt = REVARG_COMMITTISH;
793798
opt.tweak = log_setup_revisions_tweak;
794799
cmd_log_init(argc, argv, prefix, &rev, &opt);
795-
return cmd_log_walk(&rev);
800+
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
796801
}
797802

798803
/* format-patch */
@@ -2289,8 +2294,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
22892294
if (rev.ref_message_ids)
22902295
string_list_clear(rev.ref_message_ids, 0);
22912296
free(rev.ref_message_ids);
2292-
UNLEAK(rev);
2293-
return 0;
2297+
return cmd_log_deinit(0, &rev);
22942298
}
22952299

22962300
static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)

t/t4126-apply-empty.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
test_description='apply empty'
44

5-
6-
TEST_PASSES_SANITIZE_LEAK=true
75
. ./test-lib.sh
86

97
test_expect_success setup '

0 commit comments

Comments
 (0)