Re: [PATCH 1/4] repository.c: move env-related setup code back to environment.c
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Feb 27, 2018, 09:39 UTC
- Message-ID
- <CACsJy8BAsQPwgBMfK4BHB-GiKoknphuTT8n=QizU0rT6K5TB2Q@mail.gmail.com>
- In-Reply-To
- <CAPig+cRkEzN-dHh9R0cX5gOhsJ7X5evAMfpWuCnVp_QN3uz8ng@mail.gmail.com>
On Tue, Feb 27, 2018 at 1:57 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 12 quoted lines
> Can: > > char *old_gitdir = repo->gitdir; > repo->gitdir = xstrdup(...); > free(old_gitdir); > > be simplified to: > > free(repo->gitdir); > repo->gitdir = xstrdup(...); > > ?
No because I think "root" (not quoted here) could point to the same value as repo->gitdir, if you free that first, the second xstrdup() will duplicate a freed memory. See 1fb2b636c6 (set_git_dir: handle feeding gitdir to itself - 2017-09-05)
I will add a comment about this since it's not very clear from this code.
-- Duy