I have a WMI-related code, that gets an event, once new app is started. I've skipped initialization part, here is the code. Note, that everything is working, all HRESULTs are S_OK.
IEnumWbemClassObject* pEnumerator = NULL;
pSvc->ExecNotificationQuery( // IWbemServices *pSvc is initialized
bstr_t("WQL"),
bstr_t("SELECT * FROM __InstanceCreationEvent WITHIN 1 "
"WHERE TargetInstance ISA 'Win32_Process'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL, &pEnumerator);
while (pEnumerator) {
_variant_t v1, v2;
pclsObj->Get(_bstr_t(L"TargetInstance"), 0, &v1, 0, 0);
IUnknown* str = v1;
str->QueryInterface(IID_IWbemClassObject, reinterpret_cast< void** >(&pclsObj));
pclsObj->Get(bstr_t(L"Handle"), 0, &v2, 0, 0);
LONG pid{ 0 };
hr = VarI4FromStr(v2.bstrVal, LOCALE_NOUSEROVERRIDE, 409, &pid);
Internal::Inject(pid); // It's my code, not relevant here
str->Release();
pclsObj->Release();
v1.Clear();
v2.Clear();
}
This code was taken from MSDN and slightly modified. However, it leaks memory, and I have no idea why. Looking via MSVC memory profiler gives us this picture:
From my point of view - I've cleared\released everything, however, allocations, like on screenshots happens once new event arrive and they are staying forever.
I've found this question, it appears to be the same, but no answer received.
Visual Studio 2015 Update 3, up-to-date Windows 10 x64 Professional.