Re: [PATCH 14/26] setup_bare_git_dir(): fix memory leak
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Apr 27, 2017, 22:57 UTC
- Message-ID
- <alpine.DEB.2.20.1704280056070.3480@virtualbox>
- In-Reply-To
- <51f2bd16-7c55-7ba0-c963-6f725b2f79e5@kdbg.org>
Hi Hannes,
On Thu, 27 Apr 2017, Johannes Sixt wrote:
Show 31 quoted lines
> Am 26.04.2017 um 22:20 schrieb Johannes Schindelin:
> > Reported by Coverity.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> > setup.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/setup.c b/setup.c
> > index 0309c278218..0320a9ad14c 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -748,7 +748,7 @@ static const char *setup_bare_git_dir(struct strbuf
> > *cwd, int offset,
> >
> > /* --work-tree is set without --git-dir; use discovered one */
> > if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
> > - const char *gitdir;
> > + static const char *gitdir;
> >
> > gitdir = offset == cwd->len ? "." : xmemdupz(cwd->buf, offset);
> > if (chdir(cwd->buf))
> >
>
> Whoa! Look what values are assigned to the variable: Either a static string or
> allocated memory. I suspect that this does not fix a memory leak at all, but
> only shuts up Coverity.
>
> -- Hannes
>
> PS: stopping here as I'm running out of time.Sorry, I meant to amend the commit message and forgot before sending the first time: setup_git_directory() (and consequently, setup_bare_git_dir()) can only be called once.
Yes, this patch is here to shut up Coverity, as it cannot know that we are talking about a singleton here.
Ciao, Dscho