bdev/virtio_blk: fix double free on init failure

virtio_blk bdevs inherit the name string from their virtio
devices. The string is always freed on virtio device destroy, so
trying to free it as a part of bdev cleanup would always result
in a double free.

Change-Id: I47d20748ec12d9be201b9cd4f72bf89a61e80170
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/412073
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-05-22 19:23:01 +02:00 committed by Daniel Verkamp
parent 475165dffe
commit 3949140b2e

View File

@ -404,14 +404,8 @@ virtio_blk_dev_init(struct virtio_blk_dev *bvdev, uint16_t max_queues)
/* bdev is tied with the virtio device; we can reuse the name */
bdev->name = vdev->name;
if (bdev->name == NULL) {
SPDK_ERRLOG("Couldn't alloc memory for the bdev name.\n");
return -ENOMEM;
}
rc = virtio_dev_start(vdev, max_queues, 0);
if (rc != 0) {
free(bdev->name);
return rc;
}
@ -433,7 +427,6 @@ virtio_blk_dev_init(struct virtio_blk_dev *bvdev, uint16_t max_queues)
SPDK_ERRLOG("Failed to register bdev name=%s\n", bdev->name);
spdk_io_device_unregister(bvdev, NULL);
virtio_dev_stop(vdev);
free(bdev->name);
return rc;
}