diff options
-rw-r--r-- | builtin-checkout.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c index 59a0ef4ec9..141a9e1873 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -342,10 +342,12 @@ static int switch_branches(struct checkout_opts *opts, unsigned char rev[20]; int flag; memset(&old, 0, sizeof(old)); - old.path = resolve_ref("HEAD", rev, 0, &flag); + old.path = xstrdup(resolve_ref("HEAD", rev, 0, &flag)); old.commit = lookup_commit_reference_gently(rev, 1); - if (!(flag & REF_ISSYMREF)) + if (!(flag & REF_ISSYMREF)) { + free((char *)old.path); old.path = NULL; + } if (old.path && !prefixcmp(old.path, "refs/heads/")) old.name = old.path + strlen("refs/heads/"); @@ -381,7 +383,7 @@ static int switch_branches(struct checkout_opts *opts, return ret; update_refs_for_switch(opts, &old, new); - + free((char *)old.path); return post_checkout_hook(old.commit, new->commit, 1); } |