dm: check pci_vdev before using
acrn-dm runs to segmentation fault when failed to create VMs with
improper parameters.
If vdevs failed to be created, they are still be freed in deinit(),
and dereference the null pointers leads to segfault.
Acked-by: Anthony Xu
@@ -821,7 +821,7 @@ static void
pci_emul_deinit(struct vmctx *ctx, struct pci_vdev_ops *ops, int bus, int slot,
int func, struct funcinfo *fi)
{
- if (ops->vdev_deinit)
+ if (ops->vdev_deinit && fi->fi_devi)
(*ops->vdev_deinit)(ctx, fi->fi_devi, fi->fi_param);
if (fi->fi_param)
free(fi->fi_param);
