Skip to content

Commit

Permalink
Fix GetAppIdForProcess memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dmex committed Jun 26, 2021
1 parent 5502140 commit 67701a8
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions phlib/appresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ static PVOID PhpQueryStartMenuCacheInterface(
return startMenuInterface;
}

static LPMALLOC PhpQueryStartMenuMallocInterface(
VOID
)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static LPMALLOC allocInterface = NULL;

if (PhBeginInitOnce(&initOnce))
{
CoGetMalloc(MEMCTX_TASK, &allocInterface);

PhEndInitOnce(&initOnce);
}

return allocInterface;
}

static BOOLEAN PhpKernelAppCoreInitialized(
VOID
)
Expand Down Expand Up @@ -142,8 +159,12 @@ BOOLEAN PhAppResolverGetAppIdForProcess(

if (appIdText)
{
//SIZE_T appIdTextLength = IMalloc_GetSize(PhpQueryStartMenuMallocInterface(), appIdText);
//*ApplicationUserModelId = PhCreateStringEx(appIdText, appIdTextLength - sizeof(UNICODE_NULL));
//IMalloc_Free(PhpQueryStartMenuMallocInterface(), appIdText);

*ApplicationUserModelId = PhCreateString(appIdText);
RtlFreeHeap(RtlProcessHeap(), 0, appIdText);
CoTaskMemFree(appIdText);
return TRUE;
}

Expand Down Expand Up @@ -187,8 +208,12 @@ BOOLEAN PhAppResolverGetAppIdForWindow(

if (appIdText)
{
//SIZE_T appIdTextLength = IMalloc_GetSize(PhpQueryStartMenuMallocInterface(), appIdText);
//*ApplicationUserModelId = PhCreateStringEx(appIdText, appIdTextLength - sizeof(UNICODE_NULL));
//IMalloc_Free(PhpQueryStartMenuMallocInterface(), appIdText);

*ApplicationUserModelId = PhCreateString(appIdText);
RtlFreeHeap(RtlProcessHeap(), 0, appIdText);
CoTaskMemFree(appIdText);
return TRUE;
}

Expand Down Expand Up @@ -240,7 +265,6 @@ HRESULT PhAppResolverEnablePackageDebug(
)
{
HRESULT status;
PPH_LIST packageTasks = NULL;
IPackageDebugSettings* packageDebugSettings;

status = PhGetClassObject(
Expand Down Expand Up @@ -270,7 +294,6 @@ HRESULT PhAppResolverDisablePackageDebug(
)
{
HRESULT status;
PPH_LIST packageTasks = NULL;
IPackageDebugSettings* packageDebugSettings;

status = PhGetClassObject(
Expand Down Expand Up @@ -555,6 +578,7 @@ PPH_STRING PhGetPackageAppDataPath(

attributeValue = PhCreateStringFromUnicodeString(&attribute->Values.pString[2]);

// TODO: Lookup user specific environment path from process. (dmex)
if (attributePath = PhExpandEnvironmentStrings(&appdataPackages))
{
packageAppDataPath = PhConcatStringRef2(&attributePath->sr, &attributeValue->sr);
Expand Down

0 comments on commit 67701a8

Please sign in to comment.