From ffe2aae4b27ee5248fb1f33ac524290d6831cbcc Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 2 Feb 2017 16:16:53 +0000 Subject: [PATCH] xl: track size of diskws with a dedicated counter The num_disks field can change during guest lifetime. Don't use that as the size of diskws, use a dedicated counter instead. Also free diskws and reset diskws to NULL after disabling events so that it will be automatically re-created when the guest reboots. Reported-by: Fatih Acar Signed-off-by: Wei Liu Acked-by: Ian Jackson Tested-by: Fatih Acar --- tools/libxl/xl_cmdimpl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index b25ac6efa0..358757fd09 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2811,6 +2811,7 @@ static int create_domain(struct domain_create *dom_info) int ret, rc; libxl_evgen_domain_death *deathw = NULL; libxl_evgen_disk_eject **diskws = NULL; /* one per disk */ + unsigned int num_diskws = 0; void *config_data = 0; int config_len = 0; int restore_fd = -1; @@ -3119,8 +3120,9 @@ start: diskws = xmalloc(sizeof(*diskws) * d_config.num_disks); for (i = 0; i < d_config.num_disks; i++) diskws[i] = NULL; + num_diskws = d_config.num_disks; } - for (i = 0; i < d_config.num_disks; i++) { + for (i = 0; i < num_diskws; i++) { if (d_config.disks[i].removable) { ret = libxl_evenable_disk_eject(ctx, domid, d_config.disks[i].vdev, 0, &diskws[i]); @@ -3157,7 +3159,10 @@ start: libxl_event_free(ctx, event); libxl_evdisable_domain_death(ctx, deathw); deathw = NULL; - evdisable_disk_ejects(diskws, d_config.num_disks); + evdisable_disk_ejects(diskws, num_diskws); + free(diskws); + diskws = NULL; + num_diskws = 0; /* discard any other events which may have been generated */ while (!(ret = libxl_event_check(ctx, &event, LIBXL_EVENTMASK_ALL, 0,0))) { -- 2.30.2