diff options
author | Rubén Justo <rjusto@gmail.com> | 2023-06-17 08:40:43 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-17 18:02:47 +0200 |
commit | 05e717d556e5e1c7cdf69c7375d19bef226fc0dc (patch) | |
tree | b7aec41d115c625f051eb9d44f48fdb3888c9cad /branch.c | |
parent | branch: fix a leak in setup_tracking (diff) | |
download | git-05e717d556e5e1c7cdf69c7375d19bef226fc0dc.tar.xz git-05e717d556e5e1c7cdf69c7375d19bef226fc0dc.zip |
rev-parse: fix a leak with --abbrev-ref
To handle "--abbrev-ref" we use shorten_unambiguous_ref(). This
function takes a refname and returns a shortened refname, which is a
newly allocated string that needs to be freed.
Unfortunately, the refname variable is reused to receive the shortened
one. Therefore, we lose the original refname, which needs to be freed
as well, producing a leak.
This leak can be reviewed with:
$ for a in {1..10}; do git branch foo_${a}; done
$ git rev-parse --abbrev-ref refs/heads/foo_{1..10}
Direct leak of 171 byte(s) in 10 object(s) allocated from:
... in xstrdup wrapper.c
... in expand_ref refs.c
... in repo_dwim_ref refs.c
... in show_rev builtin/rev-parse.c
... in cmd_rev_parse builtin/rev-parse.c
... in run_builtin git.c
We have this leak since a45d34691e (rev-parse: --abbrev-ref option to
shorten ref name, 2009-04-13) when "--abbrev-ref" was introduced.
Let's fix it.
Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
0 files changed, 0 insertions, 0 deletions