diff mbox series

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

Message ID 56baa798fbb2838227fbc08ed54f200e38545d28.1716877224.git.ps@pks.im (mailing list archive)
State Accepted
Commit 36cf62055465ace201f03e39c4851aa5c81ffa5f
Headers show
Series refs: ref storage format migrations | expand

Commit Message

Patrick Steinhardt May 28, 2024, 6:31 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);
 }