Re: [PATCH 1/4] repository.c: move env-related setup code back to environment.c

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

 



On Tue, Feb 27, 2018 at 1:57 AM, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
> 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



[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