From 9d4c550564ee254dda9e2620c4c1e32ebb529728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 18 Jul 2023 12:31:46 +0200 Subject: [PATCH] repository: make cleanup safe for re-use with grafts We are allowed to call `git_repository__cleanup` multiple times, and this happens e.g. in rugged if we want to free up resources before GC gets around to them. This means that we cannot leave dangling pointers in it, which we were doing with the grafts. Fix this by setting the pointers to NULL after freeing the resources. --- src/libgit2/repository.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 97f776c4a34..05ece6efc41 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -153,7 +153,9 @@ int git_repository__cleanup(git_repository *repo) git_cache_clear(&repo->objects); git_attr_cache_flush(repo); git_grafts_free(repo->grafts); + repo->grafts = NULL; git_grafts_free(repo->shallow_grafts); + repo->shallow_grafts = NULL; set_config(repo, NULL); set_index(repo, NULL);