lib/virtio: add the ctx NULL check before dereferencing it

Issue is found in the virtio_pci_scsi_dev_create() whose
error path is setting the vdev->ctx to NULL before the
destruct operation.

Change-Id: I4ab0fbe300f7413ad4503833088856aa3f4c0734
Signed-off-by: GangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15676
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
GangCao 2022-11-28 23:34:47 -05:00 committed by Tomasz Zawadzki
parent fed1f52b9e
commit cebb63a7a7
2 changed files with 8 additions and 4 deletions

View File

@ -183,8 +183,10 @@ virtio_vfio_user_destruct_dev(struct virtio_dev *vdev)
{
struct virtio_vfio_user_dev *dev = vdev->ctx;
spdk_vfio_user_release(dev->ctx);
free(dev);
if (dev) {
spdk_vfio_user_release(dev->ctx);
free(dev);
}
}
static uint16_t

View File

@ -971,8 +971,10 @@ virtio_user_destroy(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = vdev->ctx;
close(dev->vhostfd);
free(dev);
if (dev) {
close(dev->vhostfd);
free(dev);
}
}
static void