mirror of
https://github.com/reactos/reactos.git
synced 2025-04-05 13:11:22 +00:00
[MSCONFIG]
- Fix memory/handle leak in failure case of GetServices. Patch by Christoph von Wittich - Fix service handle failure checks - Remove unnecessary casts svn path=/trunk/; revision=61653
This commit is contained in:
parent
20fe3bef9e
commit
f895117bca
2 changed files with 13 additions and 8 deletions
|
@ -99,7 +99,7 @@ GetServices ( void )
|
|||
ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;
|
||||
|
||||
ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
|
||||
if (ScHandle != INVALID_HANDLE_VALUE)
|
||||
if (ScHandle != NULL)
|
||||
{
|
||||
if (EnumServicesStatusEx(ScHandle, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, (LPBYTE)pServiceStatus, 0, &BytesNeeded, &NumServices, &ResumeHandle, 0) == 0)
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ GetServices ( void )
|
|||
if (GetLastError() == ERROR_MORE_DATA)
|
||||
{
|
||||
/* reserve memory for service info array */
|
||||
pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
pServiceStatus = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
if (!pServiceStatus)
|
||||
return;
|
||||
|
||||
|
@ -145,16 +145,21 @@ GetServices ( void )
|
|||
|
||||
BytesNeeded = 0;
|
||||
hService = OpenService(ScHandle, pServiceStatus[Index].lpServiceName, SC_MANAGER_CONNECT);
|
||||
if (hService != INVALID_HANDLE_VALUE)
|
||||
if (hService != NULL)
|
||||
{
|
||||
/* check if service is required by the system*/
|
||||
if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)NULL, 0, &BytesNeeded))
|
||||
{
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
pServiceFailureActions = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
if (pServiceFailureActions == NULL)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
||||
CloseServiceHandle(hService);
|
||||
CloseServiceHandle(ScHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QueryServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, (LPBYTE)pServiceFailureActions, BytesNeeded, &BytesNeeded))
|
||||
{
|
||||
|
@ -196,7 +201,7 @@ GetServices ( void )
|
|||
{
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
pServiceConfig = (LPQUERY_SERVICE_CONFIG) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
pServiceConfig = HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
|
||||
if (pServiceConfig == NULL)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
||||
|
@ -238,7 +243,7 @@ GetServices ( void )
|
|||
dwLen = GetFileVersionInfoSize(FileName, &dwHandle);
|
||||
if (dwLen)
|
||||
{
|
||||
lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);
|
||||
lpData = HeapAlloc(GetProcessHeap(), 0, dwLen);
|
||||
if (lpData == NULL)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, pServiceStatus);
|
||||
|
|
|
@ -93,7 +93,7 @@ GetDisabledAutostartEntriesFromRegistry (TCHAR * szBasePath)
|
|||
{
|
||||
dwValueLength = MAX_KEY_LENGTH;
|
||||
dwDataLength = MAX_VALUE_NAME;
|
||||
Data = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
|
||||
Data = HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
|
||||
if (Data == NULL)
|
||||
break;
|
||||
|
||||
|
@ -160,7 +160,7 @@ GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName )
|
|||
{
|
||||
dwValueLength = MAX_KEY_LENGTH;
|
||||
dwDataLength = MAX_VALUE_NAME;
|
||||
Data = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
|
||||
Data = HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
|
||||
if (Data == NULL)
|
||||
break;
|
||||
retVal = RegEnumValue(hKey, Index, lpValueName, &dwValueLength, NULL, &dwType, (LPBYTE)Data, &dwDataLength);
|
||||
|
|
Loading…
Reference in a new issue