mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
gh-125315: Avoid crashing in _wmimodule due to slow WMI calls on some Windows machines (GH-126141)
(cherry picked from commit 60c415bd53
)
Co-authored-by: Steve Dower <steve.dower@python.org>
This commit is contained in:
parent
00ff23f06d
commit
9304416e7d
2 changed files with 17 additions and 7 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Avoid crashing in :mod:`platform` due to slow WMI calls on some Windows
|
||||||
|
machines.
|
|
@ -55,12 +55,26 @@ _query_thread(LPVOID param)
|
||||||
IWbemLocator *locator = NULL;
|
IWbemLocator *locator = NULL;
|
||||||
IWbemServices *services = NULL;
|
IWbemServices *services = NULL;
|
||||||
IEnumWbemClassObject* enumerator = NULL;
|
IEnumWbemClassObject* enumerator = NULL;
|
||||||
|
HRESULT hr = S_OK;
|
||||||
BSTR bstrQuery = NULL;
|
BSTR bstrQuery = NULL;
|
||||||
struct _query_data *data = (struct _query_data*)param;
|
struct _query_data *data = (struct _query_data*)param;
|
||||||
|
|
||||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
// gh-125315: Copy the query string first, so that if the main thread gives
|
||||||
|
// up on waiting we aren't left with a dangling pointer (and a likely crash)
|
||||||
|
bstrQuery = SysAllocString(data->query);
|
||||||
|
if (!bstrQuery) {
|
||||||
|
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||||
|
}
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
CloseHandle(data->writePipe);
|
CloseHandle(data->writePipe);
|
||||||
|
if (bstrQuery) {
|
||||||
|
SysFreeString(bstrQuery);
|
||||||
|
}
|
||||||
return (DWORD)hr;
|
return (DWORD)hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +115,6 @@ _query_thread(LPVOID param)
|
||||||
NULL, EOAC_NONE
|
NULL, EOAC_NONE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (SUCCEEDED(hr)) {
|
|
||||||
bstrQuery = SysAllocString(data->query);
|
|
||||||
if (!bstrQuery) {
|
|
||||||
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
hr = services->ExecQuery(
|
hr = services->ExecQuery(
|
||||||
bstr_t("WQL"),
|
bstr_t("WQL"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue