*** a/src/port/exec.c
--- b/src/port/exec.c
***************
*** 804,810 **** AddUserToDacl(HANDLE hProcess)
  
  cleanup:
  	if (psidUser)
! 		FreeSid(psidUser);
  
  	if (pacl)
  		LocalFree((HLOCAL) pacl);
--- 804,810 ----
  
  cleanup:
  	if (psidUser)
! 		LocalFree((HLOCAL) psidUser);
  
  	if (pacl)
  		LocalFree((HLOCAL) pacl);
***************
*** 822,827 **** cleanup:
--- 822,830 ----
   * GetUserSid*PSID *ppSidUser, HANDLE hToken)
   *
   * Get the SID for the current user
+  *
+  * The caller of this function is responsible for calling LocalFree() on the
+  * returned SID area.
   */
  static BOOL
  GetUserSid(PSID *ppSidUser, HANDLE hToken)
***************
*** 838,844 **** GetUserSid(PSID *ppSidUser, HANDLE hToken)
  	{
  		if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
  		{
! 			pTokenUser = (PTOKEN_USER) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
  
  			if (pTokenUser == NULL)
  			{
--- 841,847 ----
  	{
  		if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
  		{
! 			pTokenUser = (PTOKEN_USER) LocalAlloc(LPTR, dwLength);
  
  			if (pTokenUser == NULL)
  			{
***************
*** 859,872 **** GetUserSid(PSID *ppSidUser, HANDLE hToken)
  							 dwLength,
  							 &dwLength))
  	{
! 		HeapFree(GetProcessHeap(), 0, pTokenUser);
  		pTokenUser = NULL;
  
  		log_error("could not get token information: %lu", GetLastError());
  		return FALSE;
  	}
  
! 	*ppSidUser = pTokenUser->User.Sid;
  	return TRUE;
  }
  
--- 862,895 ----
  							 dwLength,
  							 &dwLength))
  	{
! 		LocalFree(pTokenUser);
  		pTokenUser = NULL;
  
  		log_error("could not get token information: %lu", GetLastError());
  		return FALSE;
  	}
  
! 	/*
! 	 * Need to copy the data to a separate buffer, so we can free our buffer
! 	 * and let the caller free only the sid part.
! 	 */
! 	dwLength = GetLengthSid(pTokenUser->User.Sid);
! 	*ppSidUser = (PSID) LocalAlloc(LPTR, dwLength);
! 	if (!*ppSidUser)
! 	{
! 		LocalFree(pTokenUser);
! 		log_error("could not allocate %lu bytes of memory", dwLength);
! 		return FALSE;
! 	}
! 	if (!CopySid(dwLength, *ppSidUser, pTokenUser->User.Sid))
! 	{
! 		LocalFree(*ppSidUser);
! 		LocalFree(pTokenUser);
! 		log_error("could not copy SID: %lu", GetLastError());
! 		return FALSE;
! 	}
! 
! 	LocalFree(pTokenUser);
  	return TRUE;
  }
  
