Skip to content

Commit 8ef8da4

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7718682 commit 8ef8da4

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

line-log.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,3 +1327,13 @@ int line_log_filter(struct rev_info *rev)
13271327

13281328
return 0;
13291329
}
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev,
6060

6161
int line_log_print(struct rev_info *rev, struct commit *commit);
6262

63+
void line_log_free(struct rev_info *rev);
64+
6365
#endif /* LINE_LOG_H */

revision.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,11 @@ static void release_revisions_mailmap(struct string_list *mailmap)
30763076

30773077
static void release_revisions_topo_walk_info(struct topo_walk_info *info);
30783078

3079+
static void free_void_commit_list(void *list)
3080+
{
3081+
free_commit_list(list);
3082+
}
3083+
30793084
void release_revisions(struct rev_info *revs)
30803085
{
30813086
free_commit_list(revs->commits);
@@ -3093,6 +3098,10 @@ void release_revisions(struct rev_info *revs)
30933098
diff_free(&revs->pruning);
30943099
reflog_walk_info_release(revs->reflog_info);
30953100
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);
30963105
}
30973106

30983107
static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child)

t/t4217-log-limit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git log with filter options limiting the output'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup test' '

0 commit comments

Comments
 (0)