If params is NULL, xen_block_drive_create calls xen_block_drive_destroy
with drive == NULL.
Reported-by: Siteshwar Vashisht <svashisht@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/block/xen-block.c | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 5dc4ba9d076..474c12fe4ac 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -883,32 +883,29 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
QDict *driver_layer;
struct stat st;
int rc;
+ char **v;
- if (params) {
- char **v = g_strsplit(params, ":", 2);
-
- if (v[1] == NULL) {
- filename = g_strdup(v[0]);
- driver = g_strdup("raw");
- } else {
- if (strcmp(v[0], "aio") == 0) {
- driver = g_strdup("raw");
- } else if (strcmp(v[0], "vhd") == 0) {
- driver = g_strdup("vpc");
- } else {
- driver = g_strdup(v[0]);
- }
- filename = g_strdup(v[1]);
- }
-
- g_strfreev(v);
- } else {
+ if (!params) {
error_setg(errp, "no params");
- goto done;
+ return NULL;
}
- assert(filename);
- assert(driver);
+ v = g_strsplit(params, ":", 2);
+ if (v[1] == NULL) {
+ filename = g_strdup(v[0]);
+ driver = g_strdup("raw");
+ } else {
+ if (strcmp(v[0], "aio") == 0) {
+ driver = g_strdup("raw");
+ } else if (strcmp(v[0], "vhd") == 0) {
+ driver = g_strdup("vpc");
+ } else {
+ driver = g_strdup(v[0]);
+ }
+ filename = g_strdup(v[1]);
+ }
+
+ g_strfreev(v);
drive = g_new0(XenBlockDrive, 1);
drive->id = g_strdup(id);
--
2.53.0