| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Avoid crashing in :mod:`platform` due to slow WMI calls on some Windows | ||
| 2 | + machines. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,12 +55,26 @@ _query_thread(LPVOID param) | |||
| 55 | 55 | IWbemLocator *locator = NULL; | |
| 56 | 56 | IWbemServices *services = NULL; | |
| 57 | 57 | IEnumWbemClassObject* enumerator = NULL; | |
| 58 | + HRESULT hr = S_OK; | ||
| 58 | 59 | BSTR bstrQuery = NULL; | |
| 59 | 60 | struct _query_data *data = (struct _query_data*)param; | |
| 60 | 61 | ||
| 61 | - HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); | ||
| 62 | + // gh-125315: Copy the query string first, so that if the main thread gives | ||
| 63 | + // up on waiting we aren't left with a dangling pointer (and a likely crash) | ||
| 64 | + bstrQuery = SysAllocString(data->query); | ||
| 65 | + if (!bstrQuery) { | ||
| 66 | + hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + if (SUCCEEDED(hr)) { | ||
| 70 | + hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); | ||
| 71 | + } | ||
| 72 | + | ||
| 62 | 73 | if (FAILED(hr)) { | |
| 63 | 74 | CloseHandle(data->writePipe); | |
| 75 | + if (bstrQuery) { | ||
| 76 | + SysFreeString(bstrQuery); | ||
| 77 | + } | ||
| 64 | 78 | return (DWORD)hr; | |
| 65 | 79 | } | |
| 66 | 80 | ||
@@ -101,12 +115,6 @@ _query_thread(LPVOID param) | |||
| 101 | 115 | NULL, EOAC_NONE | |
| 102 | 116 | ); | |
| 103 | 117 | } | |
| 104 | - if (SUCCEEDED(hr)) { | ||
| 105 | - bstrQuery = SysAllocString(data->query); | ||
| 106 | - if (!bstrQuery) { | ||
| 107 | - hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | 118 | if (SUCCEEDED(hr)) { | |
| 111 | 119 | hr = services->ExecQuery( | |
| 112 | 120 | bstr_t("WQL"), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments