From 6ff7e3bae02a466e10006908565dfb606970ede2 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 21 Oct 2009 22:35:56 +0000 Subject: Fix for memory leak when gui is attached, submitted and fixed by GreenReaper, thanks! git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11936 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/inspircd_win32wrapper.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index bc68a2486..8291cd60d 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -652,6 +652,7 @@ int getcpu() while (pEnumerator) { VARIANT vtProp; + VariantInit(&vtProp); /* Next item */ HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); @@ -664,9 +665,10 @@ int getcpu() if (!FAILED(hr)) { /* Matches our process ID? */ - if (vtProp.uintVal == GetCurrentProcessId()) - { - VariantClear(&vtProp); + UINT pid = vtProp.uintVal; + VariantClear(&vtProp); + if (pid == GetCurrentProcessId()) + { /* Get CPU percentage for this process */ hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0); if (!FAILED(hr)) @@ -674,18 +676,19 @@ int getcpu() /* Deal with wide string ickyness. Who in their right * mind puts a number in a bstrVal wide string item?! */ - VariantClear(&vtProp); cpu = 0; std::wstringstream out(vtProp.bstrVal); out >> cpu; - break; + VariantClear(&vtProp); } + pclsObj->Release(); + break; } + pclsObj->Release(); } } pEnumerator->Release(); - pclsObj->Release(); } SysFreeString(Language); -- cgit v1.2.3