diff mbox series

[kvmtool,07/16] disk/core: Fix segfault on exit with SCSI

Message ID 20230419132119.124457-8-jean-philippe@linaro.org (mailing list archive)
State New, archived
Headers show
Series Fix vhost-net, scsi and vsock | expand

Commit Message

Jean-Philippe Brucker April 19, 2023, 1:21 p.m. UTC
The SCSI backend doesn't call disk_image__new() so the disk ops are
NULL. Check for this case on exit.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 disk/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/disk/core.c b/disk/core.c
index 45681024..35689b8e 100644
--- a/disk/core.c
+++ b/disk/core.c
@@ -223,10 +223,10 @@  static int disk_image__close(struct disk_image *disk)
 
 	disk_aio_destroy(disk);
 
-	if (disk->ops->close)
+	if (disk->ops && disk->ops->close)
 		return disk->ops->close(disk);
 
-	if (close(disk->fd) < 0)
+	if (disk->fd && close(disk->fd) < 0)
 		pr_warning("close() failed");
 
 	free(disk);