git: c3af4c1ee879 - stable/13 - kvm_close(3): Check kd->sparse_map != NULL before munmap

From: Ashish SHUKLA <ashish_at_FreeBSD.org>
Date: Wed, 26 Oct 2022 03:26:05 UTC
The branch stable/13 has been updated by ashish (ports committer):

URL: https://cgit.FreeBSD.org/src/commit/?id=c3af4c1ee8791f4e1bddd4df648c8d5cfdc62b2e

commit c3af4c1ee8791f4e1bddd4df648c8d5cfdc62b2e
Author:     Ashish SHUKLA <ashish@FreeBSD.org>
AuthorDate: 2022-08-30 08:18:51 +0000
Commit:     Ashish SHUKLA <ashish@FreeBSD.org>
CommitDate: 2022-10-26 03:23:24 +0000

    kvm_close(3): Check kd->sparse_map != NULL before munmap
    
    PR:             266113
    Reviewed by:    markj
    
    (cherry picked from commit e6901a29bc4345f12e9c85426cc2be81045020a6)
---
 lib/libkvm/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index b98f2f25e619..4b886171a7d6 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -303,7 +303,7 @@ kvm_close(kvm_t *kd)
 		free(kd->pt_map);
 	if (kd->page_map != NULL)
 		free(kd->page_map);
-	if (kd->sparse_map != MAP_FAILED)
+	if (kd->sparse_map != MAP_FAILED && kd->sparse_map != NULL)
 		munmap(kd->sparse_map, kd->pt_sparse_size);
 	free((void *)kd);