]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files: fix NULL pointer deref when releasing ref store
authorPatrick Steinhardt <ps@pks.im>
Thu, 6 Jun 2024 05:29:25 +0000 (07:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Jun 2024 16:04:32 +0000 (09:04 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/ref-cache.c

index b6c53fc8ed26068a96698c2b74f8651d776d2e16..4ce519bbc852545874eee6271f51e07eed6c0b64 100644 (file)
@@ -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);
 }