diff mbox series

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

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

Commit Message

Patrick Steinhardt June 3, 2024, 9:30 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);
 }