]> git.ipfire.org Git - thirdparty/git.git/commit
remote: fix leaks when matching refspecs
authorPatrick Steinhardt <ps@pks.im>
Thu, 22 Aug 2024 09:17:58 +0000 (11:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2024 16:18:06 +0000 (09:18 -0700)
commit5e9e04a0641a933fd2da62139795ef6fd322835a
treef9acb76ab9579d80842e7fa38f43ba48060d4ef2
parentf5ccb535ccfbabd55c2c7ab0b8e36ca5f322d31f
remote: fix leaks when matching refspecs

In `match_explicit()`, we try to match a source ref with a destination
ref according to a refspec item. This matching sometimes requires us to
allocate a new source spec so that it looks like we expect. And while we
in some end up assigning this allocated ref as `peer_ref`, which hands
over ownership of it to the caller, in other cases we don't. We neither
free it though, causing a memory leak.

Fix the leak by creating a common exit path where we can easily free the
source ref in case it is allocated and hasn't been handed over to the
caller.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
t/t5505-remote.sh