c++ - Memory-leaks with ICreateDevEnum, IEnumMoniker, BindToStorage -
when executing following code, extracted msdn, there serious memory leaks. using mingw 5.3 (same leaks mingw 4.8) , windows 7.
did forget call release() or method prevent leak ?
#include <dshow.h> #include <iostream> #include <mmdeviceapi.h> #include <uuids.h> void print_device() { // create system device enumerator. hresult hr; icreatedevenum *psysdevenum = null; hr = cocreateinstance(clsid_systemdeviceenum, null, clsctx_inproc_server, iid_icreatedevenum, (void **)&psysdevenum); if (failed(hr)) { return; } // obtain class enumerator video compressor category. ienummoniker *penumcat = null; hr = psysdevenum->createclassenumerator(clsid_videocompressorcategory, &penumcat, 0); if (hr == s_ok) { // enumerate monikers. imoniker *pmoniker = null; ulong cfetched; while(penumcat->next(1, &pmoniker, &cfetched) == s_ok) { ipropertybag *ppropbag; hr = pmoniker->bindtostorage(0, 0, iid_ipropertybag, (void **)&ppropbag); if (succeeded(hr)) { // retrieve filter's friendly name, following: variant varname; variantinit(&varname); hr = ppropbag->read(l"friendlyname", &varname, 0); if (succeeded(hr)) { std::wcout << varname.bstrval << '\n'; } variantclear(&varname); } pmoniker->release(); } penumcat->release(); } psysdevenum->release(); } int main() { // initializes coinitialize( null ); // loop test leak while( true ) { print_device(); } }
Comments
Post a Comment