From d5873072054f1c3ae198a9563839e9c7f5660fe1 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Wed, 9 May 2018 16:40:58 -0700 Subject: [PATCH 1/4] object.c: free replace map in raw_object_store_clear The replace map for objects was missed to free in the object store in the conversion of 174774cd519 (Merge branch 'sb/object-store-replace', 2018-05-08) Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- object.c | 1 + 1 file changed, 1 insertion(+) diff --git a/object.c b/object.c index 66cffaf6e5..cdf520084d 100644 --- a/object.c +++ b/object.c @@ -480,6 +480,7 @@ void raw_object_store_clear(struct raw_object_store *o) { FREE_AND_NULL(o->objectdir); FREE_AND_NULL(o->alternate_db); + FREE_AND_NULL(o->replace_map); free_alt_odbs(o); o->alt_odb_tail = NULL; From 74fd0705bb3f99f6b74d6d23d1a1b2b0a926d412 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Wed, 9 May 2018 16:40:59 -0700 Subject: [PATCH 2/4] replace-object.c: remove the_repository from prepare_replace_object This was missed in 5982da9d2ce (replace-object: allow prepare_replace_object to handle arbitrary repositories, 2018-04-11) Technically the code works correctly as the replace_map is the same size in different repositories, however it is hard to read. So convert the code to the familiar pattern of dereferencing the pointer that we assign in the sizeof itself. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- replace_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replace_object.c b/replace_object.c index 246b98cd4f..801b5c1678 100644 --- a/replace_object.c +++ b/replace_object.c @@ -37,7 +37,7 @@ static void prepare_replace_object(struct repository *r) return; r->objects->replace_map = - xmalloc(sizeof(*the_repository->objects->replace_map)); + xmalloc(sizeof(*r->objects->replace_map)); oidmap_init(r->objects->replace_map, 0); for_each_replace_ref(r, register_replace_ref, NULL); From 7a1dc605af0d76b6de5832f1a2c1587e693de6df Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 11:29:57 -0700 Subject: [PATCH 3/4] object.c: clear replace map before freeing it Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- object.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/object.c b/object.c index cdf520084d..97245fdea2 100644 --- a/object.c +++ b/object.c @@ -480,6 +480,8 @@ void raw_object_store_clear(struct raw_object_store *o) { FREE_AND_NULL(o->objectdir); FREE_AND_NULL(o->alternate_db); + + oidmap_free(o->replace_map, 1); FREE_AND_NULL(o->replace_map); free_alt_odbs(o); From 2dc417ab1fa87cbab99eaf8a293380fa763dcd2b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 May 2018 15:25:53 -0700 Subject: [PATCH 4/4] get_main_ref_store: BUG() when outside a repository If we don't have a repository, then we can't initialize the ref store. Prior to 64a741619d (refs: store the main ref store inside the repository struct, 2018-04-11), we'd try to access get_git_dir(), and outside a repository that would trigger a BUG(). After that commit, though, we directly use the_repository->git_dir; if it's NULL we'll just segfault. Let's catch this case and restore the BUG() behavior. Obviously we don't ever want to hit this code, but a BUG() is a lot more helpful than a segfault if we do. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- refs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/refs.c b/refs.c index 9b56fa9b81..4a44e44b6a 100644 --- a/refs.c +++ b/refs.c @@ -1654,6 +1654,9 @@ struct ref_store *get_main_ref_store(struct repository *r) if (r->refs) return r->refs; + if (!r->gitdir) + BUG("attempting to get main_ref_store outside of repository"); + r->refs = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS); return r->refs; }