diff --git a/samples/vboxwrapper/vbox_mscom_impl.cpp b/samples/vboxwrapper/vbox_mscom_impl.cpp index d977263161..9c6be6b0db 100644 --- a/samples/vboxwrapper/vbox_mscom_impl.cpp +++ b/samples/vboxwrapper/vbox_mscom_impl.cpp @@ -1144,7 +1144,11 @@ int VBOX_VM::deregister_vm(bool delete_media) { pMediumAttachment->get_Port(&lPort); pMediumAttachment->get_Medium(&pMedium); - mediums.push_back(CComPtr(pMedium)); + // If the device in question is a DVD/CD-ROM drive, the medium may have been ejected. + // If so, pMedium will be NULL. + if (pMedium) { + mediums.push_back(CComPtr(pMedium)); + } rc = pMachine->DetachDevice(strController, lPort, lDevice); CHECK_ERROR(rc);