]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/push.c
push: release strbufs used for refspec formatting
authorRené Scharfe <l.s.r@web.de>
Sat, 5 Sep 2020 14:47:47 +0000 (16:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 6 Sep 2020 20:15:45 +0000 (13:15 -0700)
commit30035d9c66bc2a52352e3ad42b56047f06c20326
tree72d735082b4dd68c78f6e363b86549b384cc29d8
parent3a238e539bcdfe3f9eb5010fd218640c1b499f7a
push: release strbufs used for refspec formatting

map_refspec() either returns the passed in ref string or a detached
strbuf.  This makes it hard for callers to release the possibly
allocated memory, and set_refspecs() consequently leaks it.

Let map_refspec() append any refspecs directly and release its own
strbufs after use.  Rename it to refspec_append_mapped() and don't
return anything to reflect its increased responsibility.

set_refspecs() also leaks its strbufs.  Do the same here and directly
call refspec_append() in each if branch instead of holding onto a
detached strbuf, then dispose of the allocated memory after use.  We
need to add an else branch for the final call because all the other
conditional branches already add their formatted refspec now.

setup_push_upstream() and setup_push_current() forgot to release their
strbufs as well; plug these leaks, too, while at it.

None of these leaks were likely to impact users, because the number
and sizes of refspecs are usually small and the allocations are only
done once per program run.  Clean them up nevertheless, as another
step on the long road towards zero memory leaks.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/push.c