git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] repository: prevent memory leak when releasing ref stores
@ 2024-08-05 10:56 Sven Strickroth via GitGitGadget
  2024-08-05 15:50 ` Sven Strickroth
  2024-08-05 16:28 ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Sven Strickroth via GitGitGadget @ 2024-08-05 10:56 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt, Sven Strickroth, Sven Strickroth

From: Sven Strickroth <email@cs-ware.de>

`ref_store_release` does not free the ref_store allocated in
`ref_store_init`.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
    repository: prevent memory leak when releasing ref stores

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1758%2Fcsware%2Frepository-memory-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1758/csware/repository-memory-leak-v1
Pull-Request: https://github.com/git/git/pull/1758

 repository.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/repository.c b/repository.c
index 9825a308993..46f1eadfe95 100644
--- a/repository.c
+++ b/repository.c
@@ -366,12 +366,16 @@ void repo_clear(struct repository *repo)
 		FREE_AND_NULL(repo->remote_state);
 	}
 
-	strmap_for_each_entry(&repo->submodule_ref_stores, &iter, e)
+	strmap_for_each_entry(&repo->submodule_ref_stores, &iter, e) {
 		ref_store_release(e->value);
+		free(e->value);
+	}
 	strmap_clear(&repo->submodule_ref_stores, 1);
 
-	strmap_for_each_entry(&repo->worktree_ref_stores, &iter, e)
+	strmap_for_each_entry(&repo->worktree_ref_stores, &iter, e) {
 		ref_store_release(e->value);
+		free(e->value);
+	}
 	strmap_clear(&repo->worktree_ref_stores, 1);
 
 	repo_clear_path_cache(&repo->cached_paths);

base-commit: e559c4bf1a306cf5814418d318cc0fea070da3c7
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-08-06 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 10:56 [PATCH] repository: prevent memory leak when releasing ref stores Sven Strickroth via GitGitGadget
2024-08-05 15:50 ` Sven Strickroth
2024-08-05 17:42   ` Junio C Hamano
2024-08-05 16:28 ` Junio C Hamano
2024-08-05 17:24   ` Junio C Hamano
2024-08-06  6:20     ` Patrick Steinhardt
2024-08-06 15:44       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).