]> git.ipfire.org Git - thirdparty/git.git/commitdiff
convert: fix leaking config strings
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2024 10:41:11 +0000 (12:41 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 15:47:38 +0000 (08:47 -0700)
In `read_convert_config()`, we end up reading some string values into
variables. We don't free any potentially-existing old values though,
which will result in a memory leak in case the same key has been defined
multiple times.

Fix those leaks.

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

index 61a540e212decde5a4451a2069cf69e0aee0a3d6..92ce04c406170ec4c227fce6d51dd588aa6b1a01 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1050,14 +1050,20 @@ static int read_convert_config(const char *var, const char *value,
         * The command-line will not be interpolated in any way.
         */
 
-       if (!strcmp("smudge", key))
+       if (!strcmp("smudge", key)) {
+               FREE_AND_NULL(drv->smudge);
                return git_config_string(&drv->smudge, var, value);
+       }
 
-       if (!strcmp("clean", key))
+       if (!strcmp("clean", key)) {
+               FREE_AND_NULL(drv->clean);
                return git_config_string(&drv->clean, var, value);
+       }
 
-       if (!strcmp("process", key))
+       if (!strcmp("process", key)) {
+               FREE_AND_NULL(drv->process);
                return git_config_string(&drv->process, var, value);
+       }
 
        if (!strcmp("required", key)) {
                drv->required = git_config_bool(var, value);
index 0b4997022bf88a713845f45f67ab55b03992a659..eeb2714d9d92040a85a7667bd662c64528b1d630 100755 (executable)
@@ -5,6 +5,7 @@ test_description='blob conversion via gitattributes'
 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-terminal.sh