Re: [PATCH v8 1/4] worktree: remove extra members from struct add_opts
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 24, 2018, 03:26 UTC
- Message-ID
- <CAPig+cSH1ouZBU9BT64vL5vBz4cD+UFCoFH4fZyf8JrM7dKe5Q@mail.gmail.com>
- In-Reply-To
- <20180423193848.5159-2-t.gummerer@gmail.com>
On Mon, Apr 23, 2018 at 3:38 PM, Thomas Gummerer <t.gummerer@gmail.com> wrote:
Show 22 quoted lines
> There are two members of 'struct add_opts', which are only used inside
> the 'add()' function, but being part of 'struct add_opts' they are
> needlessly also passed to the 'add_worktree' function.
>
> Make them local to the 'add()' function to make it clearer where they
> are used.
>
> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -27,8 +27,6 @@ struct add_opts {
> int keep_locked;
> - const char *new_branch;
> - int force_new_branch;
> };
> @@ -395,33 +394,32 @@ static int add(int ac, const char **av, const char *prefix)
> - if (ac < 2 && !opts.new_branch && !opts.detach) {
> + if (ac < 2 && !new_branch && !opts.detach) {
> int n;
> const char *s = worktree_basename(path, &n);
> - opts.new_branch = xstrndup(s, n);
> + new_branch = xstrndup(s, n);Sorry for not noticing this earlier, but when 'new_branch' was part of 'opts', this leaked xstrndup'd string was covered by the UNLEAK(opts) at the end of the function. However, now that 'new_branch' is a standalone variable, it needs its own UNLEAK().