ref-filter: clear reachable list pointers after freeing
In `reach_filter()`, we pop all commits from the reachable lists, leaving them empty. But because we're operating on a list pointer that was passed by value, the original `filter.reachable_from` and `filter.unreachable_from` pointers are left dangling. As is the case with the previous commit, nobody touches either of these fields after calling `reach_filter()`, so leaving them dangling is OK. But this future proofs against dangerous situations. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 10, 2023 at 17:12 UTC
311bfe18ce8563d0b1b571e9dc9eb35b97de3790
1 file changed
+7
-7
ref-filter.c
+7
-7
@@ -2418,13 +2418,13 @@ void ref_array_clear(struct ref_array *array)
2418
#define EXCLUDE_REACHED 0
2419
#define INCLUDE_REACHED 1
2420
static void reach_filter(struct ref_array *array,
2421
- struct commit_list *check_reachable,
2421
+ struct commit_list **check_reachable,
2422
int include_reached)
2423
{
2424
int i, old_nr;
2425
struct commit **to_clear;
2426
2427
- if (!check_reachable)
2427
+ if (!*check_reachable)
2428
return;
2429
2430
CALLOC_ARRAY(to_clear, array->nr);
@@ -2434,7 +2434,7 @@ static void reach_filter(struct ref_array *array,
2434
}
2435
2436
tips_reachable_from_bases(the_repository,
2437
- check_reachable,
2437
+ *check_reachable,
2438
to_clear, array->nr,
2439
UNINTERESTING);
2440
@@ -2455,8 +2455,8 @@ static void reach_filter(struct ref_array *array,
2455
2456
clear_commit_marks_many(old_nr, to_clear, ALL_REV_FLAGS);
2457
2458
- while (check_reachable) {
2459
- struct commit *merge_commit = pop_commit(&check_reachable);
2458
+ while (*check_reachable) {
2459
+ struct commit *merge_commit = pop_commit(check_reachable);
2460
clear_commit_marks(merge_commit, ALL_REV_FLAGS);
2461
}
2462
@@ -2553,8 +2553,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
2553
clear_contains_cache(&ref_cbdata.no_contains_cache);
2554
2555
/* Filters that need revision walking */
2556
- reach_filter(array, filter->reachable_from, INCLUDE_REACHED);
2557
- reach_filter(array, filter->unreachable_from, EXCLUDE_REACHED);
2556
+ reach_filter(array, &filter->reachable_from, INCLUDE_REACHED);
2557
+ reach_filter(array, &filter->unreachable_from, EXCLUDE_REACHED);
2558
2559
save_commit_buffer = save_commit_buffer_orig;
2560
return ret;