setup: free old value before setting `work_tree`
authorMartin Ågren <martin.agren@gmail.com>
Tue, 22 Jan 2019 21:45:47 +0000 (22:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jan 2019 21:15:58 +0000 (13:15 -0800)
Before assigning to `data->work_tree` in `read_worktree_config()`, free
any value we might already have picked up, so that we do not leak it.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c
diff --git a/setup.c b/setup.c
index 1be5037f129646cd46d3dc048e8f58dc3bdac0b9..bb633942bba11f8f0289ec992a6a14a3d01c975a 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -411,6 +411,7 @@ static int read_worktree_config(const char *var, const char *value, void *vdata)
        } else if (strcmp(var, "core.worktree") == 0) {
                if (!value)
                        return config_error_nonbool(var);
+               free(data->work_tree);
                data->work_tree = xstrdup(value);
        }
        return 0;