mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
wt-status: introduce wt_status_state_free_buffers()
When we have a `struct wt_status_state`, we manually free its `branch`, `onto` and `detached_from`, or sometimes just one or two of them. Provide a function `wt_status_state_free_buffers()` which does the freeing. The callers are still aware of these fields, e.g., they check whether `branch` was populated or not. But this way, they don't need to know about *all* of them, and if `struct wt_status_state` gets more fields, they will not need to learn to free them. Users of `struct wt_status` (which contains a `wt_status_state`) already have `wt_status_collect_free_buffers()` (corresponding to `wt_status_collect()`) which we can also teach to use this new helper. Finally, note that we're currently leaving dangling pointers behind. Some callers work on a stack-allocated struct, where this is obviously ok. But for the users of `run_status()` in builtin/commit.c, there are ample opportunities for someone to mistakenly use those dangling pointers. We seem to be ok for now, but it's a use-after-free waiting to happen. Let's leave NULL-pointers behind instead. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
8f7e3de097
commit
962dd7ebc3
11
wt-status.c
11
wt-status.c
@@ -778,9 +778,14 @@ void wt_status_collect(struct wt_status *s)
|
||||
|
||||
void wt_status_collect_free_buffers(struct wt_status *s)
|
||||
{
|
||||
free(s->state.branch);
|
||||
free(s->state.onto);
|
||||
free(s->state.detached_from);
|
||||
wt_status_state_free_buffers(&s->state);
|
||||
}
|
||||
|
||||
void wt_status_state_free_buffers(struct wt_status_state *state)
|
||||
{
|
||||
FREE_AND_NULL(state->branch);
|
||||
FREE_AND_NULL(state->onto);
|
||||
FREE_AND_NULL(state->detached_from);
|
||||
}
|
||||
|
||||
static void wt_longstatus_print_unmerged(struct wt_status *s)
|
||||
|
||||
Reference in New Issue
Block a user