diff --git a/dlls/advapi32/advapi32_misc.h b/dlls/advapi32/advapi32_misc.h index 9dd48b878e6..425a7bec0b8 100644 --- a/dlls/advapi32/advapi32_misc.h +++ b/dlls/advapi32/advapi32_misc.h @@ -42,6 +42,12 @@ static inline void *heap_alloc( size_t len ) return HeapAlloc( GetProcessHeap(), 0, len ); } +static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1); +static inline void *heap_alloc_zero( size_t len ) +{ + return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len ); +} + static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2); static inline void *heap_realloc( void *mem, size_t len ) { diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c index 6bfdda60bac..23ff2f048a1 100644 --- a/dlls/advapi32/service.c +++ b/dlls/advapi32/service.c @@ -51,12 +51,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(service); void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len) { - return HeapAlloc(GetProcessHeap(), 0, len); + return heap_alloc(len); } void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr) { - HeapFree(GetProcessHeap(), 0, ptr); + heap_free(ptr); } typedef struct service_data_t @@ -111,7 +111,7 @@ LPWSTR SERV_dup( LPCSTR str ) if( !str ) return NULL; len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); - wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); + wstr = heap_alloc( len*sizeof (WCHAR) ); MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len ); return wstr; } @@ -130,7 +130,7 @@ static inline LPWSTR SERV_dupmulti(LPCSTR str) len++; n++; - wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); + wstr = heap_alloc( len*sizeof (WCHAR) ); MultiByteToWideChar( CP_ACP, 0, str, n, wstr, len ); return wstr; } @@ -234,7 +234,7 @@ static LPWSTR service_get_pipe_name(void) if (ret != ERROR_SUCCESS || type != REG_DWORD) return NULL; len = sizeof(format)/sizeof(WCHAR) + 10 /* strlenW("4294967295") */; - name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + name = heap_alloc(len * sizeof(WCHAR)); if (!name) return NULL; snprintfW(name, len, format, service_current); @@ -254,7 +254,7 @@ static HANDLE service_open_pipe(void) if (GetLastError() != ERROR_PIPE_BUSY) break; } while (WaitNamedPipeW(szPipe, NMPWAIT_USE_DEFAULT_WAIT)); - HeapFree(GetProcessHeap(), 0, szPipe); + heap_free(szPipe); return handle; } @@ -294,13 +294,13 @@ static DWORD WINAPI service_thread(LPVOID arg) { LPWSTR *argv, p; - argv = HeapAlloc(GetProcessHeap(), 0, (argc+1)*sizeof(LPWSTR)); + argv = heap_alloc((argc+1)*sizeof(LPWSTR)); for (argc=0, p=str; *p; p += strlenW(p) + 1) argv[argc++] = p; argv[argc] = NULL; info->proc.w(argc, argv); - HeapFree(GetProcessHeap(), 0, argv); + heap_free(argv); } else { @@ -308,17 +308,17 @@ static DWORD WINAPI service_thread(LPVOID arg) DWORD lenA; lenA = WideCharToMultiByte(CP_ACP,0, str, len, NULL, 0, NULL, NULL); - strA = HeapAlloc(GetProcessHeap(), 0, lenA); + strA = heap_alloc(lenA); WideCharToMultiByte(CP_ACP,0, str, len, strA, lenA, NULL, NULL); - argv = HeapAlloc(GetProcessHeap(), 0, (argc+1)*sizeof(LPSTR)); + argv = heap_alloc((argc+1)*sizeof(LPSTR)); for (argc=0, p=strA; *p; p += strlen(p) + 1) argv[argc++] = p; argv[argc] = NULL; info->proc.a(argc, argv); - HeapFree(GetProcessHeap(), 0, argv); - HeapFree(GetProcessHeap(), 0, strA); + heap_free(argv); + heap_free(strA); } return 0; } @@ -336,8 +336,8 @@ static DWORD service_handle_start(service_data *service, const WCHAR *data, DWOR return ERROR_SERVICE_ALREADY_RUNNING; } - HeapFree(GetProcessHeap(), 0, service->args); - service->args = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR)); + heap_free(service->args); + service->args = heap_alloc(count * sizeof(WCHAR)); memcpy( service->args, data, count * sizeof(WCHAR) ); service->thread = CreateThread( NULL, 0, service_thread, service, 0, NULL ); @@ -390,19 +390,19 @@ static DWORD WINAPI service_control_dispatcher(LPVOID arg) if (count < info.total_size) { data_size = info.total_size - FIELD_OFFSET(service_start_info,data); - data = HeapAlloc( GetProcessHeap(), 0, data_size ); + data = heap_alloc( data_size ); r = ReadFile( disp->pipe, data, data_size, &count, NULL ); if (!r) { if (GetLastError() != ERROR_BROKEN_PIPE) ERR( "pipe read failed error %u\n", GetLastError() ); - HeapFree( GetProcessHeap(), 0, data ); + heap_free( data ); break; } if (count != data_size) { ERR( "partial pipe read %u/%u\n", count, data_size ); - HeapFree( GetProcessHeap(), 0, data ); + heap_free( data ); break; } } @@ -442,12 +442,12 @@ static DWORD WINAPI service_control_dispatcher(LPVOID arg) done: WriteFile( disp->pipe, &result, sizeof(result), &count, NULL ); - HeapFree( GetProcessHeap(), 0, data ); + heap_free( data ); } CloseHandle( disp->pipe ); CloseServiceHandle( disp->manager ); - HeapFree( GetProcessHeap(), 0, disp ); + heap_free( disp ); return 1; } @@ -459,13 +459,13 @@ static BOOL service_run_main_thread(void) DWORD i, n, ret; HANDLE wait_handles[MAXIMUM_WAIT_OBJECTS]; UINT wait_services[MAXIMUM_WAIT_OBJECTS]; - dispatcher_data *disp = HeapAlloc( GetProcessHeap(), 0, sizeof(*disp) ); + dispatcher_data *disp = heap_alloc( sizeof(*disp) ); disp->manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_CONNECT ); if (!disp->manager) { ERR("failed to open service manager error %u\n", GetLastError()); - HeapFree( GetProcessHeap(), 0, disp ); + heap_free( disp ); return FALSE; } @@ -474,7 +474,7 @@ static BOOL service_run_main_thread(void) { WARN("failed to create control pipe error %u\n", GetLastError()); CloseServiceHandle( disp->manager ); - HeapFree( GetProcessHeap(), 0, disp ); + heap_free( disp ); SetLastError( ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ); return FALSE; } @@ -590,13 +590,13 @@ BOOL WINAPI StartServiceCtrlDispatcherA( const SERVICE_TABLE_ENTRYA *servent ) return FALSE; } - services = HeapAlloc( GetProcessHeap(), 0, nb_services * sizeof(*services) ); + services = heap_alloc( nb_services * sizeof(*services) ); for (i = 0; i < nb_services; i++) { DWORD len = MultiByteToWideChar(CP_ACP, 0, servent[i].lpServiceName, -1, NULL, 0); DWORD sz = FIELD_OFFSET( service_data, name[len] ); - info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz ); + info = heap_alloc_zero( sz ); MultiByteToWideChar(CP_ACP, 0, servent[i].lpServiceName, -1, info->name, len); info->proc.a = servent[i].lpServiceProc; info->unicode = FALSE; @@ -638,13 +638,13 @@ BOOL WINAPI StartServiceCtrlDispatcherW( const SERVICE_TABLE_ENTRYW *servent ) return FALSE; } - services = HeapAlloc( GetProcessHeap(), 0, nb_services * sizeof(*services) ); + services = heap_alloc( nb_services * sizeof(*services) ); for (i = 0; i < nb_services; i++) { DWORD len = strlenW(servent[i].lpServiceName) + 1; DWORD sz = FIELD_OFFSET( service_data, name[len] ); - info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz ); + info = heap_alloc_zero( sz ); strcpyW(info->name, servent[i].lpServiceName); info->proc.w = servent[i].lpServiceProc; info->unicode = TRUE; @@ -767,14 +767,14 @@ SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus ) SC_HANDLE WINAPI OpenSCManagerA( LPCSTR lpMachineName, LPCSTR lpDatabaseName, DWORD dwDesiredAccess ) { - LPWSTR lpMachineNameW, lpDatabaseNameW; + LPWSTR machineW, databaseW; SC_HANDLE ret; - lpMachineNameW = SERV_dup(lpMachineName); - lpDatabaseNameW = SERV_dup(lpDatabaseName); - ret = OpenSCManagerW(lpMachineNameW, lpDatabaseNameW, dwDesiredAccess); - HeapFree(GetProcessHeap(), 0, lpDatabaseNameW); - HeapFree(GetProcessHeap(), 0, lpMachineNameW); + machineW = SERV_dup(lpMachineName); + databaseW = SERV_dup(lpDatabaseName); + ret = OpenSCManagerW(machineW, databaseW, dwDesiredAccess); + heap_free(databaseW); + heap_free(machineW); return ret; } @@ -925,7 +925,7 @@ SC_HANDLE WINAPI OpenServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, lpServiceNameW = SERV_dup(lpServiceName); ret = OpenServiceW( hSCManager, lpServiceNameW, dwDesiredAccess); - HeapFree(GetProcessHeap(), 0, lpServiceNameW); + heap_free(lpServiceNameW); return ret; } @@ -1059,13 +1059,13 @@ CreateServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, lpBinaryPathNameW, lpLoadOrderGroupW, lpdwTagId, lpDependenciesW, lpServiceStartNameW, lpPasswordW ); - HeapFree( GetProcessHeap(), 0, lpServiceNameW ); - HeapFree( GetProcessHeap(), 0, lpDisplayNameW ); - HeapFree( GetProcessHeap(), 0, lpBinaryPathNameW ); - HeapFree( GetProcessHeap(), 0, lpLoadOrderGroupW ); - HeapFree( GetProcessHeap(), 0, lpDependenciesW ); - HeapFree( GetProcessHeap(), 0, lpServiceStartNameW ); - HeapFree( GetProcessHeap(), 0, lpPasswordW ); + heap_free( lpServiceNameW ); + heap_free( lpDisplayNameW ); + heap_free( lpBinaryPathNameW ); + heap_free( lpLoadOrderGroupW ); + heap_free( lpDependenciesW ); + heap_free( lpServiceStartNameW ); + heap_free( lpPasswordW ); return r; } @@ -1141,8 +1141,7 @@ BOOL WINAPI StartServiceA( SC_HANDLE hService, DWORD dwNumServiceArgs, TRACE("(%p,%d,%p)\n",hService,dwNumServiceArgs,lpServiceArgVectors); if (dwNumServiceArgs) - lpwstr = HeapAlloc( GetProcessHeap(), 0, - dwNumServiceArgs*sizeof(LPWSTR) ); + lpwstr = heap_alloc( dwNumServiceArgs*sizeof(LPWSTR) ); for(i=0; i