[SERVMAN]

- 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
This commit is contained in:
Kamil Hornicek 2014-10-21 22:58:23 +00:00
parent c7f4cb10e3
commit 2ee22c5764
6 changed files with 15 additions and 11 deletions

View file

@ -52,7 +52,7 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
if(hFile != INVALID_HANDLE_VALUE) if(hFile != INVALID_HANDLE_VALUE)
{ {
TCHAR LVText[500]; TCHAR LVText[500];
TCHAR newl = _T('\n'); TCHAR newl[2] = {_T('\r'), _T('\n')};
TCHAR tab = _T('\t'); TCHAR tab = _T('\t');
DWORD dwTextLength, dwWritten; DWORD dwTextLength, dwWritten;
INT NumListedServ = 0; INT NumListedServ = 0;
@ -68,7 +68,7 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
LVText, LVText,
i, i,
k); k);
if (LVText != NULL) if (_tcslen(LVText))
{ {
WriteFile(hFile, WriteFile(hFile,
LVText, LVText,
@ -84,8 +84,8 @@ SaveServicesToFile(PMAIN_WND_INFO Info,
} }
} }
WriteFile(hFile, WriteFile(hFile,
&newl, newl,
sizeof(TCHAR), sizeof(newl),
&dwWritten, &dwWritten,
NULL); NULL);
} }

View file

@ -204,10 +204,11 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART, SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0)); (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
} }
HeapFree(GetProcessHeap(), 0, lpServiceConfig);
} }
if(lpServiceConfig)
HeapFree(GetProcessHeap(), 0, lpServiceConfig);
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) ) if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{ {
EnableMenuItem(hMainMenu, ID_STOP, MF_ENABLED); EnableMenuItem(hMainMenu, ID_STOP, MF_ENABLED);

View file

@ -167,9 +167,7 @@ CreateProgressDialog(HWND hParent,
0, 0,
(LPARAM)lpProgStr); (LPARAM)lpProgStr);
HeapFree(GetProcessHeap(), LocalFree(lpProgStr);
0,
lpProgStr);
} }
/* Finally, show and update the progress dialog */ /* Finally, show and update the progress dialog */

View file

@ -33,7 +33,6 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo,
{ {
hButton = GetDlgItem(hwndDlg, IDC_START); hButton = GetDlgItem(hwndDlg, IDC_START);
EnableWindow (hButton, TRUE); EnableWindow (hButton, TRUE);
HeapFree(GetProcessHeap(), 0, lpServiceConfig);
} }
else if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) ) else if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{ {
@ -46,6 +45,9 @@ SetButtonStates(PSERVICEPROPSHEET dlgInfo,
EnableWindow (hButton, TRUE); EnableWindow (hButton, TRUE);
} }
if(lpServiceConfig)
HeapFree(GetProcessHeap(), 0, lpServiceConfig);
hButton = GetDlgItem(hwndDlg, IDC_START_PARAM); hButton = GetDlgItem(hwndDlg, IDC_START_PARAM);
EnableWindow(hButton, (State == SERVICE_STOPPED)); EnableWindow(hButton, (State == SERVICE_STOPPED));

View file

@ -270,6 +270,7 @@ GetServiceList(PMAIN_WND_INFO Info,
HeapFree(ProcessHeap, HeapFree(ProcessHeap,
0, 0,
Info->pAllServices); Info->pAllServices);
Info->pAllServices = NULL;
} }
ScHandle = OpenSCManager(NULL, ScHandle = OpenSCManager(NULL,
@ -319,7 +320,7 @@ GetServiceList(PMAIN_WND_INFO Info,
if (ScHandle) if (ScHandle)
CloseServiceHandle(ScHandle); CloseServiceHandle(ScHandle);
if (!bRet) if (!bRet && Info->pAllServices)
{ {
HeapFree(ProcessHeap, HeapFree(ProcessHeap,
0, 0,

View file

@ -163,6 +163,8 @@ AddServiceNamesToStop(HWND hServiceListBox,
LB_ADDSTRING, LB_ADDSTRING,
0, 0,
(LPARAM)lpServiceConfig->lpDisplayName); (LPARAM)lpServiceConfig->lpDisplayName);
HeapFree(GetProcessHeap(), 0, lpServiceConfig);
} }
/* Move onto the next string */ /* Move onto the next string */