diff options
-rw-r--r-- | ref-filter.c | 4 | ||||
-rw-r--r-- | worktree.c | 5 | ||||
-rw-r--r-- | wt-status.c | 11 | ||||
-rw-r--r-- | wt-status.h | 7 |
4 files changed, 18 insertions, 9 deletions
diff --git a/ref-filter.c b/ref-filter.c index 8ba0e31915..ea00ca38c8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1509,9 +1509,7 @@ char *get_head_description(void) strbuf_addstr(&desc, _("no branch")); strbuf_addch(&desc, ')'); - free(state.branch); - free(state.onto); - free(state.detached_from); + wt_status_state_free_buffers(&state); return strbuf_detach(&desc, NULL); } diff --git a/worktree.c b/worktree.c index 62217b4a6b..62a7eb9342 100644 --- a/worktree.c +++ b/worktree.c @@ -357,8 +357,7 @@ int is_worktree_being_rebased(const struct worktree *wt, state.branch && starts_with(target, "refs/heads/") && !strcmp(state.branch, target + strlen("refs/heads/"))); - free(state.branch); - free(state.onto); + wt_status_state_free_buffers(&state); return found_rebase; } @@ -373,7 +372,7 @@ int is_worktree_being_bisected(const struct worktree *wt, state.branch && starts_with(target, "refs/heads/") && !strcmp(state.branch, target + strlen("refs/heads/")); - free(state.branch); + wt_status_state_free_buffers(&state); return found_rebase; } diff --git a/wt-status.c b/wt-status.c index 4a7483ee7d..4345eb1749 100644 --- a/wt-status.c +++ b/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) diff --git a/wt-status.h b/wt-status.h index f1fa0ec1a7..35b44c388e 100644 --- a/wt-status.h +++ b/wt-status.h @@ -151,7 +151,14 @@ void wt_status_add_cut_line(FILE *fp); void wt_status_prepare(struct repository *r, struct wt_status *s); void wt_status_print(struct wt_status *s); void wt_status_collect(struct wt_status *s); +/* + * Frees the buffers allocated by wt_status_collect. + */ void wt_status_collect_free_buffers(struct wt_status *s); +/* + * Frees the buffers of the wt_status_state. + */ +void wt_status_state_free_buffers(struct wt_status_state *s); void wt_status_get_state(struct repository *repo, struct wt_status_state *state, int get_detached_from); |