]> Kevux Git Server - rit/commitdiff
builtin/submodule--helper: fix leaking remote ref on errors
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:46:21 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:35 +0000 (08:25 -0700)
When `update_submodule()` fails we return with `die_message()`, which
only causes us to print the same message as `die()` would without
actually causing the process to die. We don't free memory in that case
and thus leak memory.

Fix the leak by freeing the remote ref.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/t7420-submodule-set-url.sh

index ff1376f..a9bd93a 100644 (file)
@@ -2648,15 +2648,20 @@ static int update_submodule(struct update_data *update_data)
 
                if (!update_data->nofetch) {
                        if (fetch_in_submodule(update_data->sm_path, update_data->depth,
-                                             0, NULL))
+                                             0, NULL)) {
+                               free(remote_ref);
                                return die_message(_("Unable to fetch in submodule path '%s'"),
                                                   update_data->sm_path);
+                       }
                }
 
                if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
-                                            remote_ref, &update_data->oid))
-                       return die_message(_("Unable to find %s revision in submodule path '%s'"),
-                                          remote_ref, update_data->sm_path);
+                                            remote_ref, &update_data->oid)) {
+                       ret = die_message(_("Unable to find %s revision in submodule path '%s'"),
+                                         remote_ref, update_data->sm_path);
+                       free(remote_ref);
+                       return ret;
+               }
 
                free(remote_ref);
        }
index bf7f15e..d7fe910 100755 (executable)
@@ -10,6 +10,7 @@ as expected.
 '
 
 TEST_NO_CREATE_REPO=1
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '