[SERVMAN]
authorKamil Hornicek <kamil.hornicek@reactos.org>
Tue, 21 Oct 2014 22:58:23 +0000 (22:58 +0000)
committerKamil Hornicek <kamil.hornicek@reactos.org>
Tue, 21 Oct 2014 22:58:23 +0000 (22:58 +0000)
- fix resource leaks CID 716292, 716293, 716294
- fix CID 716772 (double free), 513719 (wrong NULL check), 1206739 (cosmetic)
- make line endings CR LF when exporting the services list

svn path=/trunk/; revision=64882

reactos/base/applications/mscutils/servman/export.c
reactos/base/applications/mscutils/servman/mainwnd.c
reactos/base/applications/mscutils/servman/progress.c
reactos/base/applications/mscutils/servman/propsheet_general.c
reactos/base/applications/mscutils/servman/query.c
reactos/base/applications/mscutils/servman/stop_dependencies.c

index f637a5d..3df3c44 100644 (file)
@@ -52,7 +52,7 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
     if(hFile != INVALID_HANDLE_VALUE)
     {
         TCHAR LVText[500];
-        TCHAR newl = _T('\n');
+        TCHAR newl[2] = {_T('\r'), _T('\n')};
         TCHAR tab = _T('\t');
         DWORD dwTextLength, dwWritten;
         INT NumListedServ = 0;
@@ -68,7 +68,7 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
                                                    LVText,
                                                    i,
                                                    k);
-                if (LVText != NULL)
+                if (_tcslen(LVText))
                 {
                     WriteFile(hFile,
                               LVText,
@@ -84,8 +84,8 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
                 }
             }
             WriteFile(hFile,
-                      &newl,
-                      sizeof(TCHAR),
+                      newl,
+                      sizeof(newl),
                       &dwWritten,
                       NULL);
         }
index 6823379..8291481 100644 (file)
@@ -204,9 +204,10 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
                 SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
                        (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
             }
+        }
 
+        if(lpServiceConfig)
             HeapFree(GetProcessHeap(), 0, lpServiceConfig);
-        }
 
         if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
         {
index e3c2d6b..8c9c843 100644 (file)
@@ -167,9 +167,7 @@ CreateProgressDialog(HWND hParent,
                                 0,
                                 (LPARAM)lpProgStr);
 
-            HeapFree(GetProcessHeap(),
-                     0,
-                     lpProgStr);
+            LocalFree(lpProgStr);
         }
 
         /* Finally, show and update the progress dialog */
index 9c33a97..6bac4cd 100644 (file)
@@ -33,7 +33,6 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo,
     {
         hButton = GetDlgItem(hwndDlg, IDC_START);
         EnableWindow (hButton, TRUE);
-        HeapFree(GetProcessHeap(), 0, lpServiceConfig);
     }
     else if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
     {
@@ -46,6 +45,9 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo,
         EnableWindow (hButton, TRUE);
     }
 
+    if(lpServiceConfig)
+        HeapFree(GetProcessHeap(), 0, lpServiceConfig);
+
     hButton = GetDlgItem(hwndDlg, IDC_START_PARAM);
     EnableWindow(hButton, (State == SERVICE_STOPPED));
 
index 14a68e5..3a5e82c 100644 (file)
@@ -270,6 +270,7 @@ GetServiceList(PMAIN_WND_INFO Info,
         HeapFree(ProcessHeap,
                      0,
                      Info->pAllServices);
+        Info->pAllServices = NULL;
     }
 
     ScHandle = OpenSCManager(NULL,
@@ -319,7 +320,7 @@ GetServiceList(PMAIN_WND_INFO Info,
     if (ScHandle)
         CloseServiceHandle(ScHandle);
 
-    if (!bRet)
+    if (!bRet && Info->pAllServices)
     {
         HeapFree(ProcessHeap,
                  0,
index 559002c..99b60bb 100644 (file)
@@ -163,6 +163,8 @@ AddServiceNamesToStop(HWND hServiceListBox,
                          LB_ADDSTRING,
                          0,
                          (LPARAM)lpServiceConfig->lpDisplayName);
+
+            HeapFree(GetProcessHeap(), 0, lpServiceConfig);
         }
 
         /* Move onto the next string */