Re: [PATCH 10/15] commit.c: fix a memory leak
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 21, 2015, 03:59 UTC
- Message-ID
- <xmqqk2ybatm1.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1426897692-18322-11-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 27 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> builtin/commit.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 961e467..da79ac4 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -229,7 +229,7 @@ static int commit_index_files(void)
> static int list_paths(struct string_list *list, const char *with_tree,
> const char *prefix, const struct pathspec *pattern)
> {
> - int i;
> + int i, ret;
> char *m;
>
> if (!pattern->nr)
> @@ -256,7 +256,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
> item->util = item; /* better a valid pointer than a fake one */
> }
>
> - return report_path_error(m, pattern, prefix);
> + ret = report_path_error(m, pattern, prefix);
> + free(m);
> + return ret;
> }Looks correct.
A tangent. We may want to move report_path_error() to somewhere more "common"-ish, like dir.c which is where we have bulk of pathspec matching infrastructure. Seeing the function used from builtin/ls-files.c makes me feel dirty.
A further tangent (Duy Cc'ed for this point). We might want to rethink the interface to ce_path_match() and report_path_error() so that we do not have to do a separate allocation of "has this pathspec been used?" array. This was a remnant from the olden days back when pathspec were mere "const char **" where we did not have any room to add per-item bit---these days pathspec is repreasented as an array of "struct pathspec" and we can afford to add a bit to the structure---which will make this kind of leak much less likely to happen.