git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] repository: fix free problem with repo_clear(the_repository)
@ 2018-05-09 17:04 Nguyễn Thái Ngọc Duy
  2018-05-09 17:17 ` Brandon Williams
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-05-09 17:04 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

the_repository is special. One of the special things about it is that
it does not allocate a new index_state object like submodules but
points to the global the_index variable instead. As a global variable,
the_index cannot be free()'d.

Add an exception for this in repo_clear(). In the future perhaps we
would be able to allocate the_repository's index on heap too. Then we
can remove revert this.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I was trying to test the new parsed_object_pool_clear() and found this.

 repository.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/repository.c b/repository.c
index a4848c1bd0..f44733524a 100644
--- a/repository.c
+++ b/repository.c
@@ -238,7 +238,9 @@ void repo_clear(struct repository *repo)
 
 	if (repo->index) {
 		discard_index(repo->index);
-		FREE_AND_NULL(repo->index);
+		if (repo->index != &the_index)
+			free(repo->index);
+		repo->index = NULL;
 	}
 }
 
-- 
2.17.0.705.g3525833791


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

end of thread, other threads:[~2018-05-10 16:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-09 17:04 [PATCH] repository: fix free problem with repo_clear(the_repository) Nguyễn Thái Ngọc Duy
2018-05-09 17:17 ` Brandon Williams
2018-05-09 17:42 ` Elijah Newren
2018-05-09 17:54   ` Duy Nguyen
2018-05-09 17:50 ` Stefan Beller
2018-05-09 18:00   ` Duy Nguyen
2018-05-09 18:09     ` Stefan Beller
2018-05-10  6:18     ` Duy Nguyen
2018-05-10  9:27   ` Junio C Hamano
2018-05-10 16:34     ` Stefan Beller
2018-05-10  6:13 ` [PATCH v2] " Nguyễn Thái Ngọc Duy

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).