Open jijieming opened 4 months ago
Thanks for reporting the issue!
Do you know where the exception is thrown?
I did a quick analysis, maybe line 421 in wmi.cpp needs to be copied to line 415 in wmi.cpp, so this:
....
try {
std::size_t index = 0;
foreachObject(pClassObject, [&out,&index](IWbemClassObject *object)
{
foreachProperty(object, [&out,index](const wstring &name, const std::wstring &value)
{
out.set(index,name, value);
return true;
});
index++;
return true;
});
} catch (const WmiException &) {
pServices->Release();
pLocator->Release();
CoUninitialize();
throw;
}
pClassObject->Release();
pServices->Release();
pLocator->Release();
CoUninitialize();
...
becomes this:
...
try {
std::size_t index = 0;
foreachObject(pClassObject, [&out,&index](IWbemClassObject *object)
{
foreachProperty(object, [&out,index](const wstring &name, const std::wstring &value)
{
out.set(index,name, value);
return true;
});
index++;
return true;
});
} catch (const WmiException &) {
pClassObject->Release(); /* this line was added */
pServices->Release();
pLocator->Release();
CoUninitialize();
throw;
}
pClassObject->Release();
pServices->Release();
pLocator->Release();
CoUninitialize();
...
Can you please test and check if this fixes the issue?
After the exception is caught here, does the program loop call, as in the example, cause a handle or memory leak:();
Win32_ComputerSystemProduct product = retrieveWmi();
SoftwareLicensingService liscense = retrieveWmi();
Win32_OperatingSystem os_info = retrieveWmi();
int main(int /argc/, char /args*/[]) { try { Win32_ComputerSystem computer = retrieveWmi