c++ - Why is this COM code leaking? -


i'm maintaining application uses windows explorer overlay icons. operations require me forcibly refresh explorers view particular folder. using following function uses com:

void refreshexplorerview(cstring strpath) {     ccomptr<ishellwindows> pshellwindows;      coinitialize(null);      if(succeeded(pshellwindows.cocreateinstance(clsid_shellwindows)))     {         idispatch* pfolder=null;         variant variant;         v_vt(&variant) = vt_i4;          for(v_i4(&variant) = 0; pshellwindows->item(variant, &pfolder) == s_ok; v_i4(&variant)++)         {             ccomptr<iwebbrowserapp> pwebbrowserapp;             if(succeeded(pfolder->queryinterface(iid_ppv_args(&pwebbrowserapp))))             {                 bstr locationurl = null;                 pwebbrowserapp->get_locationurl(&locationurl);                  if(locationurl != null && strpath.comparenocase(locationurl) == 0)                 {                     ccomptr<iserviceprovider> pserviceprovider;                     if(succeeded(pwebbrowserapp->queryinterface(iid_ppv_args(&pserviceprovider))))                     {                         ccomptr<ishellbrowser> pshellbrowser;                         if(succeeded(pserviceprovider->queryinterface(iid_ppv_args(&pshellbrowser))))                         {                             ishellview* pshellview;                             if(succeeded(pshellbrowser->queryactiveshellview(&pshellview)))                             {                                 pshellview->refresh();                                 pshellview->release();                             }                         }                     }                 }                  sysfreestring(locationurl);             }             pfolder->release();             pfolder = null;         }     }      couninitialize(); } 

i've noticed when program refresh regularly grows in size , umdh has shown me appear leaking pfolder , pshellwindow instances every time runs. can't work out why on earth happens since far can tell these released properly. can see i'm missing?

you release pshellwindows after couninitialize, incorrect.

the rest of interfaces seem released fine. note improve cleanless , readability greatly using ccomqiptr instead of queryinterface, , not using raw pointers @ (bstr, ifoo*) , replace them smart auto-releasing wrappers.

pfolder might leaking too, if item call successful returns code other s_ok. again, use of ccomptr<ifolder> instead of ifolder* resolve problem without drawing attention it.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -