From 759f34073807119ffb935a84aa86e6a8fa7a9bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 4 Mar 2022 19:32:17 +0100 Subject: repository.c: free the "path cache" in repo_clear() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "struct path_cache" added in 102de880d24 (path.c: migrate global git_path_* to take a repository argument, 2018-05-17) is only used directly by code in repository.[ch] (but populated in path.[ch]). Let's move this code to repository.[ch], and stop leaking this memory when we run repo_clear(). To avoid the cast change it from a "const char *" to a "char *". This also removes the "PATH_CACHE_INIT" macro, which has never been used for anything. For the "struct repository" we already make a hard assumption that it (and "the_repository") can be identically initialized by making it a "static" variable, so making use of a "PATH_CACHE_INIT" somewhere would have been confusing. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- repository.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'repository.c') diff --git a/repository.c b/repository.c index 34610c5a33..9b86f3f121 100644 --- a/repository.c +++ b/repository.c @@ -240,6 +240,20 @@ out: return ret; } +static void repo_clear_path_cache(struct repo_path_cache *cache) +{ + FREE_AND_NULL(cache->squash_msg); + FREE_AND_NULL(cache->squash_msg); + FREE_AND_NULL(cache->merge_msg); + FREE_AND_NULL(cache->merge_rr); + FREE_AND_NULL(cache->merge_mode); + FREE_AND_NULL(cache->merge_head); + FREE_AND_NULL(cache->merge_autostash); + FREE_AND_NULL(cache->auto_merge); + FREE_AND_NULL(cache->fetch_head); + FREE_AND_NULL(cache->shallow); +} + void repo_clear(struct repository *repo) { FREE_AND_NULL(repo->gitdir); @@ -280,6 +294,8 @@ void repo_clear(struct repository *repo) remote_state_clear(repo->remote_state); FREE_AND_NULL(repo->remote_state); } + + repo_clear_path_cache(&repo->cached_paths); } int repo_read_index(struct repository *repo) -- cgit v1.2.3