checkout: plug some leaks in git-restorerj/restore-plug-leaks
commit2f64da0790900f9c83f697730047282b7d22f5b5
authorRubén Justo <rjusto@gmail.com>
Thu, 14 Mar 2024 18:08:58 +0000 (14 19:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Mar 2024 18:58:04 +0000 (14 11:58 -0700)
tree114cebad0588be8f577eb1c9932ec1c7658f21a1
parent3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0
checkout: plug some leaks in git-restore

In git-restore we need to free the pathspec and pathspec_from_file
values from the struct checkout_opts.

A simple fix could be to free them in cmd_restore, after the call to
checkout_main returns, like we are doing [1][2] in the sibling function
cmd_checkout.

However, we can do even better.

We have git-switch and git-restore, both of them spin-offs[3][4] of
git-checkout.  All three are implemented as thin wrappers around
checkout_main.  Considering this, it makes a lot of sense to do the
cleanup closer to checkout_main.

Move the cleanups, including the new_branch_info variable, to
checkout_main.

As a consequence, mark: t2070, t2071, t2072 and t6418 as leak-free.

 [1] 9081a421a6 (checkout: fix "branch info" memory leaks, 2021-11-16)

 [2] 7ce4088ab7 (parse-options: consistently allocate memory in
     fix_filename(), 2023-03-04)

 [3] d787d311db (checkout: split part of it to new command 'switch',
     2019-03-29)

 [4] 46e91b663b (checkout: split part of it to new command 'restore',
     2019-04-25)

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
t/t2070-restore.sh
t/t2071-restore-patch.sh
t/t2072-restore-pathspec-file.sh
t/t6418-merge-text-auto.sh