diff mbox series

[v5,07/12] refs/files: fix NULL pointer deref when releasing ref store

Message ID 6b0aaf2ac829fe2c223a7e7b6ea0d86732a6a0eb.1717649802.git.ps@pks.im (mailing list archive)
State Accepted
Commit b3e098d6e77db87946c50c3517fbdeffe9168ca9
Headers show
Series refs: ref storage migrations | expand

Commit Message

Patrick Steinhardt June 6, 2024, 5:29 a.m. UTC
The `free_ref_cache()` function is not `NULL` safe and will thus
segfault when being passed such a pointer. This can easily happen when
trying to release a partially initialized "files" ref store. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/ref-cache.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index b6c53fc8ed..4ce519bbc8 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -71,6 +71,8 @@  static void free_ref_entry(struct ref_entry *entry)
 
 void free_ref_cache(struct ref_cache *cache)
 {
+	if (!cache)
+		return;
 	free_ref_entry(cache->root);
 	free(cache);
 }