revision: clear decoration structs during release_revisions()

The point of release_revisions() is to free memory associated with the rev_info struct, but we have several "struct decoration" members that are left untouched. Since the previous commit introduced a function to do that, we can just call it. We do have to provide some specialized callbacks to map the void pointers onto real ones (the alternative would be casting the existing function pointers; this generally works because "void *" is usually interchangeable with a struct pointer, but it is technically forbidden by the standard). Since the line-log code does not expose the type it stores in the decoration (nor of course the function to free it), I put this behind a generic line_log_free() entry point. It's possible we may need to add more line-log specific bits anyway (running t4211 shows a number of other leaks in the line-log code). While this doubtless cleans up many leaks triggered by the test suite, the only script which becomes leak-free is t4217, as it does very little beyond a simple traversal (its existing leak was from the use of --children, which is now fixed). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 5, 2023 at 17:30 UTC 8ef8da484272587c5c30810e5fcb03b4048a1221
4 files changed +22
line-log.c
+10
@@ -1327,3 +1327,13 @@ int line_log_filter(struct rev_info *rev)
1327
1328 return 0;
1329 }
1330 +
1331 +static void free_void_line_log_data(void *data)
1332 +{
1333 + free_line_log_data(data);
1334 +}
1335 +
1336 +void line_log_free(struct rev_info *rev)
1337 +{
1338 + clear_decoration(&rev->line_log_data, free_void_line_log_data);
1339 +}
line-log.h
+2
@@ -60,4 +60,6 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev,
60
61 int line_log_print(struct rev_info *rev, struct commit *commit);
62
63 +void line_log_free(struct rev_info *rev);
64 +
65 #endif /* LINE_LOG_H */
revision.c
+9
@@ -3076,6 +3076,11 @@ static void release_revisions_mailmap(struct string_list *mailmap)
3076
3077 static void release_revisions_topo_walk_info(struct topo_walk_info *info);
3078
3079 +static void free_void_commit_list(void *list)
3080 +{
3081 + free_commit_list(list);
3082 +}
3083 +
3084 void release_revisions(struct rev_info *revs)
3085 {
3086 free_commit_list(revs->commits);
@@ -3093,6 +3098,10 @@ void release_revisions(struct rev_info *revs)
3098 diff_free(&revs->pruning);
3099 reflog_walk_info_release(revs->reflog_info);
3100 release_revisions_topo_walk_info(revs->topo_walk_info);
3101 + clear_decoration(&revs->children, free_void_commit_list);
3102 + clear_decoration(&revs->merge_simplification, free);
3103 + clear_decoration(&revs->treesame, free);
3104 + line_log_free(revs);
3105 }
3106
3107 static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child)
t/t4217-log-limit.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='git log with filter options limiting the output'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup test' '