Index: trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
===================================================================
--- trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 49950)
+++ trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 50025)
@@ -364,5 +364,6 @@
                         if (dwLength)
                         {
-                            pProc->pSid = (PSID)RTMemAlloc(dwLength);
+                            pProc->pSid = (PSID)HeapAlloc(GetProcessHeap(),
+                                                          HEAP_ZERO_MEMORY, dwLength);
                             AssertPtr(pProc->pSid);
                             if (CopySid(dwLength, pProc->pSid, pUser->User.Sid))
@@ -378,6 +379,13 @@
 
                         if (dwErr != ERROR_SUCCESS)
+                        {
                             VBoxServiceError("Error retrieving SID of process PID=%ld: %ld\n",
                                              pProc->id, dwErr);
+                            if (pProc->pSid)
+                            {
+                                HeapFree(GetProcessHeap(), 0 /* Flags */, pProc->pSid);
+                                pProc->pSid = NULL;
+                            }
+                        }
                         break;
                     }
@@ -457,4 +465,5 @@
         }
     } while (cProcesses <= _32K); /* Should be enough; see: http://blogs.technet.com/markrussinovich/archive/2009/07/08/3261309.aspx */
+
     if (RT_SUCCESS(rc))
     {
@@ -495,5 +504,5 @@
             }
             else
-                RTMemFree(paProcs);
+                VBoxServiceVMInfoWinProcessesFree(cProcesses, paProcs);
         }
         else
@@ -516,5 +525,9 @@
     {
         if (paProcs[i].pSid)
-            RTMemFree(paProcs[i].pSid);
+        {
+            HeapFree(GetProcessHeap(), 0 /* Flags */, paProcs[i].pSid);
+            paProcs[i].pSid = NULL;
+        }
+
     }
     RTMemFree(paProcs);
@@ -992,4 +1005,7 @@
     AssertRC(rc2);
 
+    char *pszUserList = NULL;
+    uint32_t cUsersInList = 0;
+
     /* This function can report stale or orphaned interactive logon sessions
        of already logged off users (especially in Windows 2000). */
@@ -1139,5 +1155,4 @@
                                cUniqueUsers);
 
-            *pcUsersInList = 0;
             for (ULONG i = 0; i < cUniqueUsers; i++)
             {
@@ -1159,11 +1174,11 @@
                                        pUserInfo[i].wszUser, pUserInfo[i].ulNumProcs, pUserInfo[i].ulLastSession);
 
-                    if (*pcUsersInList > 0)
+                    if (cUsersInList > 0)
                     {
-                        rc = RTStrAAppend(ppszUserList, ",");
-                        AssertRCBreakStmt(rc, RTStrFree(*ppszUserList));
+                        rc = RTStrAAppend(&pszUserList, ",");
+                        AssertRCBreakStmt(rc, RTStrFree(pszUserList));
                     }
 
-                    *pcUsersInList += 1;
+                    cUsersInList += 1;
 
                     char *pszUser = NULL;
@@ -1176,5 +1191,5 @@
                     {
                         /* Append user to users list. */
-                        rc = RTStrAAppend(ppszUserList, pszUser);
+                        rc = RTStrAAppend(&pszUserList, pszUser);
 
                         /* Do idle detection. */
@@ -1183,10 +1198,10 @@
                     }
                     else
-                        rc = RTStrAAppend(ppszUserList, "<string-conversion-error>");
+                        rc = RTStrAAppend(&pszUserList, "<string-conversion-error>");
 
                     RTStrFree(pszUser);
                     RTStrFree(pszDomain);
 
-                    AssertRCBreakStmt(rc, RTStrFree(*ppszUserList));
+                    AssertRCBreakStmt(rc, RTStrFree(pszUserList));
                 }
             }
@@ -1198,4 +1213,10 @@
     if (paSessions)
         LsaFreeReturnBuffer(paSessions);
+
+    if (RT_SUCCESS(rc))
+    {
+        *ppszUserList = pszUserList;
+        *pcUsersInList = cUsersInList;
+    }
 
     s_uDebugIter++;
