BOF.NET icon indicating copy to clipboard operation
BOF.NET copied to clipboard

Leak of memory for BSTR friendlyName due to missing call to SysFreeString

Open JohnLaTwC opened this issue 2 years ago • 0 comments

A BSTR friendlyName is declared but not freed in the main body of getAppDomain and the memory is leaked as a result

    while((hr = icrh->NextDomain(hDomainEnum, &iu)) == S_OK){

!        BSTR friendlyName;   <<< BSTR declared

...

!        hr = appDomain->get_FriendlyName(&friendlyName);   <<< BSTR allocated and returned

        if(friendlyName && wcscmp(friendlyName, appDomainName) == 0){
            iu->Release();
            found = true;
+            SysFreeString on friendlyName
            break;
        }

        hr = appDomain->Load_2(SysAllocString(L"BOFNET"), &assembly);

        if(assembly == nullptr){
            iu->Release();
+            SysFreeString on friendlyName
            continue;
        }

        found = true;
        iu->Release();
+            SysFreeString on friendlyName
        break;
    }

https://github.com/CCob/BOF.NET/blob/1ef41fe9f6a60b8f4d1838ecfb04a91d137878b5/bofs/bofnet_execute.cpp#L115

JohnLaTwC avatar Aug 14 '23 20:08 JohnLaTwC