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
This commit is contained in:
Magnus Olsen 2006-06-30 22:07:54 +00:00
parent a05350a500
commit 11963867d1

View file

@ -442,7 +442,8 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpServiceNameW) if (!lpServiceNameW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto cleanup;
return NULL;
} }
MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, lpServiceNameW, len); MultiByteToWideChar(CP_ACP, 0, lpServiceName, -1, lpServiceNameW, len);
} }
@ -454,7 +455,9 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpDisplayNameW) if (!lpDisplayNameW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto cleanup;
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
return NULL;
} }
MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpDisplayNameW, len); MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpDisplayNameW, len);
} }
@ -466,7 +469,10 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpBinaryPathNameW) if (!lpBinaryPathNameW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); 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); MultiByteToWideChar(CP_ACP, 0, lpDisplayName, -1, lpBinaryPathNameW, len);
} }
@ -478,7 +484,11 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpLoadOrderGroupW) if (!lpLoadOrderGroupW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); 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); MultiByteToWideChar(CP_ACP, 0, lpLoadOrderGroup, -1, lpLoadOrderGroupW, len);
} }
@ -498,7 +508,12 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpDependenciesW) if (!lpDependenciesW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); 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); MultiByteToWideChar(CP_ACP, 0, lpDependencies, -1, lpDependenciesW, dwDependenciesLength);
} }
@ -510,7 +525,13 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpServiceStartNameW) if (!lpServiceStartNameW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); 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); MultiByteToWideChar(CP_ACP, 0, lpServiceStartName, -1, lpServiceStartNameW, len);
} }
@ -522,7 +543,14 @@ CreateServiceA(SC_HANDLE hSCManager,
if (!lpPasswordW) if (!lpPasswordW)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); 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); MultiByteToWideChar(CP_ACP, 0, lpPassword, -1, lpPasswordW, len);
} }
@ -541,7 +569,7 @@ CreateServiceA(SC_HANDLE hSCManager,
lpServiceStartNameW, lpServiceStartNameW,
lpPasswordW); lpPasswordW);
cleanup:
HeapFree(GetProcessHeap(), 0, lpServiceNameW); HeapFree(GetProcessHeap(), 0, lpServiceNameW);
HeapFree(GetProcessHeap(), 0, lpDisplayNameW); HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW); HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW);