none
CreateProcessAsUser memory leak

    Question

  • Hello,

    I have a service that run the following code.

    Every time that CreateProcessAsUser is hit, the memory increase in 4K (I can see it in the Task Manager).

    Where am I wrong?

    PWTS_SESSION_INFO pSessionInfo = 0;
    DWORD dwCount = 0;
    int dwSessionId = 0;
    WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwCount);
    for(DWORD i = 0; i < dwCount; ++i)
    {
    	WTS_SESSION_INFO si = pSessionInfo[i];
    	if (WTSActive == si.State)
    	{
    		dwSessionId = si.SessionId;
    		break;
    	}
    }
    WTSFreeMemory(pSessionInfo);
    HANDLE currentToken;
    BOOL bRet = WTSQueryUserToken(dwSessionId, &currentToken);
    if (bRet == false)
    {
    	return 0;
    }
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);
    if (CreateProcessAsUser(currentToken, "MY_EXE.exe", "MY_ARGS_STR", NULL, NULL, false, 0, NULL, NULL, &si, &pi))
    {
    	if (pi.hProcess != NULL)
    	{
    		CloseHandle(pi.hProcess);
    	}
    	if (pi.hThread != NULL)
    	{
    		CloseHandle(pi.hThread);
    	}
    }
    CloseHandle(currentToken);
    return 0;

    Wednesday, December 12, 2012 12:14 PM

All replies

  • Hi,
     
    Welcome here.
     
    Based on your description, your issue is about CreateProcessAsUser API, so I’d like to move this thread to Microsoft SDK for better support.
     
    Thanks for your understanding.

    Regards,


    Elegentin Xie
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 9:59 AM