Thread (103 messages) flat view 103 messages, 6 authors, 2018-02-28

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

From: Duy Nguyen <hidden>
Date: 2018-02-27 09:40:04

On Tue, Feb 27, 2018 at 1:57 AM, Eric Sunshine [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help