CrystalDiskInfo icon indicating copy to clipboard operation
CrystalDiskInfo copied to clipboard

Fix resource leaks

Open Bobini1 opened this issue 1 year ago • 1 comments

I have found two places in the code where resources are not released correctly.

It is possible to revert the deletion of SAFE_RELEASE(pCOMDev); from line 64 if you believe VariantInit, VariantClear or IWbemClassObject::Get could throw an exception that would skip over line 56.

EDIT: I have found two more places where resources can be leaked.

Bobini1 avatar Mar 18 '24 11:03 Bobini1

The error handling logic is already quite messy, and all this leaking issue can be trivially fixed by simply replacing all the raw COM pointers with a smart pointer ComPtr (or better use wil that also provides HRESULT error checking). @hiyohiyo What do you think?

HO-COOH avatar May 02 '25 16:05 HO-COOH