Skip to content

Commit

Permalink
branch: FREE_AND_NULL instead of NULL'ing real_ref
Browse files Browse the repository at this point in the history
real_ref was previously populated by dwim_ref(), which allocates new
memory. We need to make sure to free real_ref when discarding it.
(real_ref is already being freed at the end of create_branch() - but
if we discard it early then it will leak.)

This fixes the following leak found while running t0002-t0099:

Direct leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x486954 in strdup /home/abuild/rpmbuild/BUILD/llvm-11.0.0.src/build/../projects/compiler-rt/lib/asan/asan_interceptors.cpp:452:3
    #1 0xdd6484 in xstrdup wrapper.c:29:14
    git-l10n#2 0xc0f658 in expand_ref refs.c:671:12
    git-l10n#3 0xc0ecf1 in repo_dwim_ref refs.c:644:22
    git-l10n#4 0x8b1184 in dwim_ref ./refs.h:162:9
    git-l10n#5 0x8b0b02 in create_branch branch.c:284:10
    git-l10n#6 0x550cbb in update_refs_for_switch builtin/checkout.c:1046:4
    git-l10n#7 0x54e275 in switch_branches builtin/checkout.c:1274:2
    git-l10n#8 0x548828 in checkout_branch builtin/checkout.c:1668:9
    git-l10n#9 0x541306 in checkout_main builtin/checkout.c:2025:9
    git-l10n#10 0x5395fa in cmd_checkout builtin/checkout.c:2077:8
    git-l10n#11 0x4d02a8 in run_builtin git.c:467:11
    git-l10n#12 0x4cbfe9 in handle_builtin git.c:719:3
    git-l10n#13 0x4cf04f in run_argv git.c:808:4
    git-l10n#14 0x4cb85a in cmd_main git.c:939:19
    git-l10n#15 0x820cf6 in main common-main.c:52:11
    git-l10n#16 0x7f30bd9dd349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Signed-off-by: Andrzej Hunt <ajrhunt@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
ahunt authored and gitster committed Apr 28, 2021
1 parent b180c68 commit d895804
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion branch.c
Expand Up @@ -294,7 +294,7 @@ void create_branch(struct repository *r,
if (explicit_tracking)
die(_(upstream_not_branch), start_name);
else
real_ref = NULL;
FREE_AND_NULL(real_ref);
}
break;
default:
Expand Down

0 comments on commit d895804

Please sign in to comment.