mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-28 22:18:04 +00:00
dm: passthru: fix potentail mem leaks
Fix potential memory leakage in some error case handling. Tracked-On: #2704 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
This commit is contained in:
parent
caa291c094
commit
4d0419ed71
@ -793,7 +793,8 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||||||
ptdev = calloc(1, sizeof(struct passthru_dev));
|
ptdev = calloc(1, sizeof(struct passthru_dev));
|
||||||
if (ptdev == NULL) {
|
if (ptdev == NULL) {
|
||||||
warnx("%s: calloc FAIL!", __func__);
|
warnx("%s: calloc FAIL!", __func__);
|
||||||
return -ENOMEM;
|
error = -ENOMEM;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptdev->phys_bdf = PCI_BDF(bus, slot, func);
|
ptdev->phys_bdf = PCI_BDF(bus, slot, func);
|
||||||
@ -802,7 +803,7 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||||||
|
|
||||||
error = pciaccess_init();
|
error = pciaccess_init();
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
return error;
|
goto done;
|
||||||
|
|
||||||
error = -ENODEV;
|
error = -ENODEV;
|
||||||
iter = pci_slot_match_iterator_create(NULL);
|
iter = pci_slot_match_iterator_create(NULL);
|
||||||
@ -817,7 +818,7 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
warnx("No physical PCI device %x:%x.%x!", bus, slot, func);
|
warnx("No physical PCI device %x:%x.%x!", bus, slot, func);
|
||||||
return -ENODEV;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
pci_device_probe(ptdev->phys_dev);
|
pci_device_probe(ptdev->phys_dev);
|
||||||
@ -867,7 +868,9 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||||||
error = 0; /* success */
|
error = 0; /* success */
|
||||||
done:
|
done:
|
||||||
if (error) {
|
if (error) {
|
||||||
|
if (ptdev != NULL) {
|
||||||
free(ptdev);
|
free(ptdev);
|
||||||
|
}
|
||||||
vm_unassign_ptdev(ctx, bus, slot, func);
|
vm_unassign_ptdev(ctx, bus, slot, func);
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
Loading…
Reference in New Issue
Block a user