Re: [PATCH] ref-filter.c: fix a leak in get_head_description

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 25 2022, Rubén Justo wrote:

> In 2708ce62d2 (branch: sort detached HEAD based on a flag, 2021-01-07) a
> call to wt_status_state_free_buffers, responsible of freeing the
> resources that could be allocated in the local struct wt_status_state
> state, was eliminated.
>
> The call to wt_status_state_free_buffers was introduced in 962dd7ebc3
> (wt-status: introduce wt_status_state_free_buffers(), 2020-09-27).  This
> commit brings back that call in get_head_description.
>
> Signed-off-by: Rubén Justo <rjusto@xxxxxxxxx>
>
> ---
>  ref-filter.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index fd1cb14b0f..914908fac5 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1722,6 +1722,8 @@ char *get_head_description(void)
>  	} else
>  		strbuf_addstr(&desc, _("(no branch)"));
>  
> +	wt_status_state_free_buffers(&state);
> +
>  	return strbuf_detach(&desc, NULL);
>  }

Thanks, this looks good to me. FWIW I have a local (still unsubmitted)
series of leak fixes across the tree which fixed this leak, that commit
is presented below as a "I've already been running with this for a
while" data point.

Thanks!

-- >8 --
Subject: [PATCH] wt-status API users: use wt_status_state_free_buffers(), fix
 leaks

Fix a memory that was accidentally introduced in ref-filter.c in
2708ce62d21 (branch: sort detached HEAD based on a flag, 2021-01-07),
and one that's been present in builtin/checkout.c since
c45f0f525de (switch: reject if some operation is in progress,
2019-03-29).

In both cases we should be using the wt_status_state_free_buffers()
API introduced in 962dd7ebc3e (wt-status: introduce
wt_status_state_free_buffers(), 2020-09-27).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 builtin/checkout.c | 2 ++
 ref-filter.c       | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 54373424403..549c3d17a1a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1469,6 +1469,8 @@ static void die_if_some_operation_in_progress(void)
 		      "or \"git worktree add\"."));
 	if (state.bisect_in_progress)
 		warning(_("you are switching branch while bisecting"));
+
+	wt_status_state_free_buffers(&state);
 }
 
 static int checkout_branch(struct checkout_opts *opts,
diff --git a/ref-filter.c b/ref-filter.c
index 45908d4bdfc..81278ec3cf7 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1722,6 +1722,8 @@ char *get_head_description(void)
 	} else
 		strbuf_addstr(&desc, _("(no branch)"));
 
+	wt_status_state_free_buffers(&state);
+
 	return strbuf_detach(&desc, NULL);
 }




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux