cpp_client_telemetry icon indicating copy to clipboard operation
cpp_client_telemetry copied to clipboard

GetAppLocalTempDirectory leaks a RoInitialize call

Open kithymel opened this issue 9 months ago • 0 comments

In Microsoft::Applications::Events::GetAppLocalTempDirectory (lib/utils/utils.cpp), we have this block of code:

auto hr = RoInitialize(RO_INIT_MULTITHREADED) /* Ignoring result from call toRoInitialize as either initialzation is successful, or else already * initialized and it should be ok to proceed in both the scenarios */ UNREFERENCED_PARAMETER(hr);

If you call RoInitialize without a matching call to RoUninitialize, you leak the com initialization on this thread. See the guidance at https://learn.microsoft.com/en-us/windows/win32/api/roapi/nf-roapi-roinitialize:

Each successful call to RoInitialize, including those that return S_FALSE, must be balanced by a corresponding call to RoUninitialize.

This is caught by Application Verifier as AVRF_STOP_THREADPOOL_DIRTY_COM_STATE.

kithymel avatar Mar 04 '25 20:03 kithymel