All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Derrick Stolee" <derrickstolee@github.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 14/14] repository.c: free the "path cache" in repo_clear()
Date: Fri,  4 Mar 2022 19:32:17 +0100	[thread overview]
Message-ID: <patch-v2-14.14-d70a4394f2b-20220304T182902Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-00.14-00000000000-20220304T182902Z-avarab@gmail.com>

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 <avarab@gmail.com>
---
 path.h       | 14 --------------
 repository.c | 16 ++++++++++++++++
 repository.h | 14 +++++++++++++-
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/path.h b/path.h
index b68691a86b8..0a59c85a62e 100644
--- a/path.h
+++ b/path.h
@@ -169,20 +169,6 @@ void report_linked_checkout_garbage(void);
 		return r->cached_paths.var; \
 	}
 
-struct path_cache {
-	const char *squash_msg;
-	const char *merge_msg;
-	const char *merge_rr;
-	const char *merge_mode;
-	const char *merge_head;
-	const char *merge_autostash;
-	const char *auto_merge;
-	const char *fetch_head;
-	const char *shallow;
-};
-
-#define PATH_CACHE_INIT { 0 }
-
 const char *git_path_squash_msg(struct repository *r);
 const char *git_path_merge_msg(struct repository *r);
 const char *git_path_merge_rr(struct repository *r);
diff --git a/repository.c b/repository.c
index 34610c5a33e..9b86f3f1214 100644
--- a/repository.c
+++ b/repository.c
@@ -240,6 +240,20 @@ int repo_submodule_init(struct repository *subrepo,
 	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)
diff --git a/repository.h b/repository.h
index ca837cb9e91..e29f361703d 100644
--- a/repository.h
+++ b/repository.h
@@ -44,6 +44,18 @@ struct repo_settings {
 	int core_multi_pack_index;
 };
 
+struct repo_path_cache {
+	char *squash_msg;
+	char *merge_msg;
+	char *merge_rr;
+	char *merge_mode;
+	char *merge_head;
+	char *merge_autostash;
+	char *auto_merge;
+	char *fetch_head;
+	char *shallow;
+};
+
 struct repository {
 	/* Environment */
 	/*
@@ -82,7 +94,7 @@ struct repository {
 	/*
 	 * Contains path to often used file names.
 	 */
-	struct path_cache cached_paths;
+	struct repo_path_cache cached_paths;
 
 	/*
 	 * Path to the repository's graft file.
-- 
2.35.1.1248.gb68c9165ad8


  parent reply	other threads:[~2022-03-04 18:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 17:10 [PATCH 00/14] tree-wide: small fixes for memory leaks Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 01/14] index-pack: fix " Ævar Arnfjörð Bjarmason
2022-03-02 20:36   ` Derrick Stolee
2022-03-03 16:19     ` Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 02/14] merge-base: free() allocated "struct commit **" list Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 03/14] diff.c: free "buf" in diff_words_flush() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 04/14] urlmatch.c: add and use a *_release() function Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 05/14] remote-curl.c: free memory in cmd_main() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 06/14] bundle: call strvec_clear() on allocated strvec Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 07/14] transport: stop needlessly copying bundle header references Ævar Arnfjörð Bjarmason
2022-03-02 20:47   ` Derrick Stolee
2022-03-03 16:20     ` Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 08/14] submodule--helper: fix trivial leak in module_add() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 09/14] commit-graph: fix memory leak in misused string_list API Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 10/14] commit-graph: stop fill_oids_from_packs() progress on error and free() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 11/14] lockfile API users: simplify and don't leak "path" Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 12/14] range-diff: plug memory leak in common invocation Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 13/14] range-diff: plug memory leak in read_patches() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 14/14] repository.c: free the "path cache" in repo_clear() Ævar Arnfjörð Bjarmason
2022-03-02 20:58 ` [PATCH 00/14] tree-wide: small fixes for memory leaks Derrick Stolee
2022-03-04 18:32 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 01/14] index-pack: fix " Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 02/14] merge-base: free() allocated "struct commit **" list Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 03/14] diff.c: free "buf" in diff_words_flush() Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 04/14] urlmatch.c: add and use a *_release() function Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 05/14] remote-curl.c: free memory in cmd_main() Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 06/14] bundle: call strvec_clear() on allocated strvec Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 07/14] transport: stop needlessly copying bundle header references Ævar Arnfjörð Bjarmason
2022-03-04 19:10     ` Derrick Stolee
2022-03-04 18:32   ` [PATCH v2 08/14] submodule--helper: fix trivial leak in module_add() Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 09/14] commit-graph: fix memory leak in misused string_list API Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 10/14] commit-graph: stop fill_oids_from_packs() progress on error and free() Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 11/14] lockfile API users: simplify and don't leak "path" Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 12/14] range-diff: plug memory leak in common invocation Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` [PATCH v2 13/14] range-diff: plug memory leak in read_patches() Ævar Arnfjörð Bjarmason
2022-03-04 18:32   ` Ævar Arnfjörð Bjarmason [this message]
2022-03-04 19:11   ` [PATCH v2 00/14] tree-wide: small fixes for memory leaks Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-v2-14.14-d70a4394f2b-20220304T182902Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.