@matheusbsbs / matheus-bagliano / commits / 55fe225dde
Fork 0

submodule--helper: fix leak of core.worktree value

In the ensure_core_worktree() function, we load the core.worktree value of the submodule repository using repo_config_get_string(). This function copies the string, but we never free it, leaking the memory. We can instead use the "tmp" version of that function to avoid the allocation at all. We don't have to worry about lifetime issues, since we never even look at the value (we just want to know if it's set). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 17, 2020 at 17:33 UTC 55fe225dde455ae32b9bc963bef4aabb9f5f7c3e
1 file changed +2 -2
builtin/submodule--helper.c
+2 -2
@@ -2101,7 +2101,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
2101 {
2102 const struct submodule *sub;
2103 const char *path;
2104 - char *cw;
2104 + const char *cw;
2105 struct repository subrepo;
2106
2107 if (argc != 2)
@@ -2116,7 +2116,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
2116 if (repo_submodule_init(&subrepo, the_repository, sub))
2117 die(_("could not get a repository handle for submodule '%s'"), path);
2118
2119 - if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {
2119 + if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
2120 char *cfg_file, *abs_path;
2121 const char *rel_path;
2122 struct strbuf sb = STRBUF_INIT;