]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/rebase.c: fix "options.onto_name" leak
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Feb 2023 19:08:10 +0000 (20:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Feb 2023 00:03:52 +0000 (16:03 -0800)
Similar to the existing "squash_onto_name" added in [1] we need to
free() the xstrdup()'d "options.onto.name" added for "--keep-base" in
[2]..

1. 9dba809a69a (builtin rebase: support --root, 2018-09-04)
2. 414d924beb4 (rebase: teach rebase --keep-base, 2019-08-27)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rebase.c
t/t3416-rebase-onto-threedots.sh

index 2ec3ae0b42eabdf9c85eb420a3af03d72923c935..41e96f0eb5ac734859197b621d4ff7c2c9f91b59 100644 (file)
@@ -1039,6 +1039,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
        struct string_list strategy_options = STRING_LIST_INIT_NODUP;
        struct object_id squash_onto;
        char *squash_onto_name = NULL;
+       char *keep_base_onto_name = NULL;
        int reschedule_failed_exec = -1;
        int allow_preemptive_ff = 1;
        int preserve_merges_selected = 0;
@@ -1675,7 +1676,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                strbuf_addstr(&buf, options.upstream_name);
                strbuf_addstr(&buf, "...");
                strbuf_addstr(&buf, branch_name);
-               options.onto_name = xstrdup(buf.buf);
+               options.onto_name = keep_base_onto_name = xstrdup(buf.buf);
        } else if (!options.onto_name)
                options.onto_name = options.upstream_name;
        if (strstr(options.onto_name, "...")) {
@@ -1851,6 +1852,7 @@ cleanup:
        free(options.strategy);
        strbuf_release(&options.git_format_patch_opt);
        free(squash_onto_name);
+       free(keep_base_onto_name);
        string_list_clear(&strategy_options, 0);
        return !!ret;
 }
index ea501f2b42b8cc43394192d11051992605bfb619..f8c4ed78c9ef7ffd0fa970525bf3cab47842b55a 100755 (executable)
@@ -5,6 +5,7 @@ test_description='git rebase --onto A...B'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-rebase.sh"