From 11963867d1f9ee0f4f6dcedbcc5c3376f28d240b Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Fri, 30 Jun 2006 22:07:54 +0000 Subject: [PATCH] CreateServiceA 1. Do not try todo HeapFree when pointer is NULL in cleanup: 2. Remove goto cleanup code 3. Rewrote the code so it does not need goto svn path=/trunk/; revision=22732 --- reactos/dll/win32/advapi32/service/scm.c | 44 +++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/reactos/dll/win32/advapi32/service/scm.c b/reactos/dll/win32/advapi32/service/scm.c index 107bfe2040b..59dceec511a 100644 --- a/reactos/dll/win32/advapi32/service/scm.c +++ b/reactos/dll/win32/advapi32/service/scm.c @@ -442,7 +442,8 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpServiceNameW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, lpServiceNameW, len); } @@ -454,7 +455,9 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpDisplayNameW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpDisplayNameW, len); } @@ -466,7 +469,10 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpBinaryPathNameW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + HeapFree(GetProcessHeap(), 0, lpDisplayNameW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpBinaryPathNameW, len); } @@ -478,7 +484,11 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpLoadOrderGroupW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + HeapFree(GetProcessHeap(), 0, lpDisplayNameW); + HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, lpLoadOrderGroupW, len); } @@ -498,7 +508,12 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpDependenciesW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + HeapFree(GetProcessHeap(), 0, lpDisplayNameW); + HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW); + HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpDependencies, -1, lpDependenciesW, dwDependenciesLength); } @@ -510,7 +525,13 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpServiceStartNameW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + HeapFree(GetProcessHeap(), 0, lpDisplayNameW); + HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW); + HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW); + HeapFree(GetProcessHeap(), 0, lpDependenciesW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, lpServiceStartNameW, len); } @@ -522,7 +543,14 @@ CreateServiceA(SC_HANDLE hSCManager, if (!lpPasswordW) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - goto cleanup; + + HeapFree(GetProcessHeap(), 0, lpServiceNameW); + HeapFree(GetProcessHeap(), 0, lpDisplayNameW); + HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW); + HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW); + HeapFree(GetProcessHeap(), 0, lpDependenciesW); + HeapFree(GetProcessHeap(), 0, lpServiceStartNameW); + return NULL; } MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, lpPasswordW, len); } @@ -541,7 +569,7 @@ CreateServiceA(SC_HANDLE hSCManager, lpServiceStartNameW, lpPasswordW); -cleanup: + HeapFree(GetProcessHeap(), 0, lpServiceNameW); HeapFree(GetProcessHeap(), 0, lpDisplayNameW); HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW);