qemu: Fix crash when updating media with shared device

Mimic the fix done in 02b9097274d1330c2e1dca7f598880e09b5c2aa0 to fix crash by
accessing an already freed structure. Also copy the explaining comment why the
pointer can't be accessed any more.
(cherry picked from commit 43b6f304bce5937f1e3a852b20b52a772b39b95f)
This commit is contained in:
Peter Krempa 2013-04-02 23:15:00 +02:00 committed by Eric Blake
parent 5fdccc8557
commit 2a702717ce

View File

@ -6073,14 +6073,17 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
goto end; goto end;
ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, force); ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, force);
/* 'disk' must not be accessed now - it has been freed.
* 'orig_disk' now points to the new disk, while 'dev_copy'
* now points to the old disk */
/* Need to remove the shared disk entry for the original
* disk src if the operation is either ejecting or updating.
*/
if (ret == 0) { if (ret == 0) {
dev->data.disk = NULL; dev->data.disk = NULL;
/* Need to remove the shared disk entry for the original ignore_value(qemuRemoveSharedDisk(driver, dev_copy->data.disk,
* disk src if the operation is either ejecting or updating. vm->def->name));
*/
if (orig_disk->src && STRNEQ_NULLABLE(orig_disk->src, disk->src))
ignore_value(qemuRemoveSharedDisk(driver, dev_copy->data.disk,
vm->def->name));
} }
break; break;
default: default: