Commit 6136b547 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

services: Use standard C functions for memory allocation.

parent 4192ee26
......@@ -102,8 +102,8 @@ static void sc_notify_release(struct sc_notify_handle *notify)
if (r == 0)
{
CloseHandle(notify->event);
HeapFree(GetProcessHeap(), 0, notify->params_list);
HeapFree(GetProcessHeap(), 0, notify);
free(notify->params_list);
free(notify);
}
}
......@@ -197,22 +197,22 @@ static void free_service_strings(struct service_entry *old, struct service_entry
QUERY_SERVICE_CONFIGW *new_cfg = &new->config;
if (old_cfg->lpBinaryPathName != new_cfg->lpBinaryPathName)
HeapFree(GetProcessHeap(), 0, old_cfg->lpBinaryPathName);
free(old_cfg->lpBinaryPathName);
if (old_cfg->lpLoadOrderGroup != new_cfg->lpLoadOrderGroup)
HeapFree(GetProcessHeap(), 0, old_cfg->lpLoadOrderGroup);
free(old_cfg->lpLoadOrderGroup);
if (old_cfg->lpServiceStartName != new_cfg->lpServiceStartName)
HeapFree(GetProcessHeap(), 0, old_cfg->lpServiceStartName);
free(old_cfg->lpServiceStartName);
if (old_cfg->lpDisplayName != new_cfg->lpDisplayName)
HeapFree(GetProcessHeap(), 0, old_cfg->lpDisplayName);
free(old_cfg->lpDisplayName);
if (old->dependOnServices != new->dependOnServices)
HeapFree(GetProcessHeap(), 0, old->dependOnServices);
free(old->dependOnServices);
if (old->dependOnGroups != new->dependOnGroups)
HeapFree(GetProcessHeap(), 0, old->dependOnGroups);
free(old->dependOnGroups);
}
/* Check if the given handle is of the required type and allows the requested access. */
......@@ -281,7 +281,7 @@ DWORD __cdecl svcctl_OpenSCManagerW(
return ERROR_INVALID_NAME;
}
if (!(manager = HeapAlloc(GetProcessHeap(), 0, sizeof(*manager))))
if (!(manager = malloc(sizeof(*manager))))
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
manager->hdr.type = SC_HTYPE_MANAGER;
......@@ -304,7 +304,7 @@ static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle)
case SC_HTYPE_MANAGER:
{
struct sc_manager_handle *manager = (struct sc_manager_handle *)hdr;
HeapFree(GetProcessHeap(), 0, manager);
free(manager);
break;
}
case SC_HTYPE_SERVICE:
......@@ -319,7 +319,7 @@ static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle)
}
service_unlock(service->service_entry);
release_service(service->service_entry);
HeapFree(GetProcessHeap(), 0, service);
free(service);
break;
}
default:
......@@ -418,7 +418,7 @@ static DWORD create_handle_for_service(struct service_entry *entry, DWORD dwDesi
{
struct sc_service_handle *service;
if (!(service = HeapAlloc(GetProcessHeap(), 0, sizeof(*service))))
if (!(service = malloc(sizeof(*service))))
{
release_service(entry);
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
......@@ -494,7 +494,7 @@ static DWORD parse_dependencies(const WCHAR *dependencies, struct service_entry
if (!len_services) entry->dependOnServices = NULL;
else
{
services = HeapAlloc(GetProcessHeap(), 0, (len_services + 1) * sizeof(WCHAR));
services = malloc((len_services + 1) * sizeof(WCHAR));
if (!services)
return ERROR_OUTOFMEMORY;
......@@ -516,10 +516,10 @@ static DWORD parse_dependencies(const WCHAR *dependencies, struct service_entry
if (!len_groups) entry->dependOnGroups = NULL;
else
{
groups = HeapAlloc(GetProcessHeap(), 0, (len_groups + 1) * sizeof(WCHAR));
groups = malloc((len_groups + 1) * sizeof(WCHAR));
if (!groups)
{
HeapFree(GetProcessHeap(), 0, services);
free(services);
return ERROR_OUTOFMEMORY;
}
s = groups;
......@@ -591,10 +591,10 @@ static DWORD create_serviceW(
entry->config.dwServiceType = entry->status.dwServiceType = dwServiceType;
entry->config.dwStartType = dwStartType;
entry->config.dwErrorControl = dwErrorControl;
entry->config.lpBinaryPathName = strdupW(lpBinaryPathName);
entry->config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
entry->config.lpServiceStartName = strdupW(lpServiceStartName);
entry->config.lpDisplayName = strdupW(lpDisplayName);
entry->config.lpBinaryPathName = wcsdup(lpBinaryPathName);
entry->config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
entry->config.lpServiceStartName = wcsdup(lpServiceStartName);
entry->config.lpDisplayName = wcsdup(lpDisplayName);
if (lpdwTagId) /* TODO: In most situations a non-NULL TagId will generate an ERROR_INVALID_PARAMETER. */
entry->config.dwTagId = *lpdwTagId;
......@@ -702,12 +702,12 @@ DWORD __cdecl svcctl_QueryServiceConfigW(
config->dwServiceType = service->service_entry->config.dwServiceType;
config->dwStartType = service->service_entry->config.dwStartType;
config->dwErrorControl = service->service_entry->config.dwErrorControl;
config->lpBinaryPathName = strdupW(service->service_entry->config.lpBinaryPathName);
config->lpLoadOrderGroup = strdupW(service->service_entry->config.lpLoadOrderGroup);
config->lpBinaryPathName = wcsdup(service->service_entry->config.lpBinaryPathName);
config->lpLoadOrderGroup = wcsdup(service->service_entry->config.lpLoadOrderGroup);
config->dwTagId = service->service_entry->config.dwTagId;
config->lpDependencies = NULL; /* TODO */
config->lpServiceStartName = strdupW(service->service_entry->config.lpServiceStartName);
config->lpDisplayName = strdupW(service->service_entry->config.lpDisplayName);
config->lpServiceStartName = wcsdup(service->service_entry->config.lpServiceStartName);
config->lpDisplayName = wcsdup(service->service_entry->config.lpDisplayName);
service_unlock(service->service_entry);
return ERROR_SUCCESS;
......@@ -802,16 +802,16 @@ DWORD __cdecl svcctl_ChangeServiceConfigW(
/* configuration OK. The strings needs to be duplicated */
if (lpBinaryPathName != NULL)
new_entry.config.lpBinaryPathName = strdupW(lpBinaryPathName);
new_entry.config.lpBinaryPathName = wcsdup(lpBinaryPathName);
if (lpLoadOrderGroup != NULL)
new_entry.config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
new_entry.config.lpLoadOrderGroup = wcsdup(lpLoadOrderGroup);
if (lpServiceStartName != NULL)
new_entry.config.lpServiceStartName = strdupW(lpServiceStartName);
new_entry.config.lpServiceStartName = wcsdup(lpServiceStartName);
if (lpDisplayName != NULL)
new_entry.config.lpDisplayName = strdupW(lpDisplayName);
new_entry.config.lpDisplayName = wcsdup(lpDisplayName);
/* try to save to Registry, commit or rollback depending on success */
err = save_service_config(&new_entry);
......@@ -841,8 +841,7 @@ static void fill_notify(struct sc_notify_handle *notify, struct service_entry *s
SC_RPC_NOTIFY_PARAMS_LIST *list;
SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2 *cparams;
list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(SC_RPC_NOTIFY_PARAMS_LIST) + sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2));
list = calloc(1, sizeof(SC_RPC_NOTIFY_PARAMS_LIST) + sizeof(SERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2));
if (!list)
return;
......@@ -937,13 +936,13 @@ DWORD __cdecl svcctl_ChangeServiceConfig2W( SC_RPC_HANDLE hService, SC_RPC_CONFI
if (config.descr->lpDescription[0])
{
if (!(descr = strdupW( config.descr->lpDescription )))
if (!(descr = wcsdup( config.descr->lpDescription )))
return ERROR_NOT_ENOUGH_MEMORY;
}
WINE_TRACE( "changing service %p descr to %s\n", service, wine_dbgstr_w(descr) );
service_lock( service->service_entry );
HeapFree( GetProcessHeap(), 0, service->service_entry->description );
free( service->service_entry->description );
service->service_entry->description = descr;
save_service_config( service->service_entry );
service_unlock( service->service_entry );
......@@ -1197,7 +1196,7 @@ BOOL process_send_control(struct process_entry *process, BOOL shared_process, co
/* calculate how much space we need to send the startup info */
len = (lstrlenW(name) + 1) * sizeof(WCHAR) + data_size;
ssi = HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info, data[len]));
ssi = malloc(FIELD_OFFSET(service_start_info, data[len]));
ssi->magic = SERVICE_PROTOCOL_MAGIC;
ssi->control = control;
ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
......@@ -1206,7 +1205,7 @@ BOOL process_send_control(struct process_entry *process, BOOL shared_process, co
if (data_size) memcpy(&ssi->data[ssi->name_size * sizeof(WCHAR)], data, data_size);
r = process_send_command(process, ssi, ssi->total_size, result);
HeapFree( GetProcessHeap(), 0, ssi );
free(ssi);
return r;
}
......@@ -1705,7 +1704,7 @@ DWORD __cdecl svcctl_NotifyServiceStatusChange(
return ERROR_CALL_NOT_IMPLEMENTED;
}
notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*notify));
notify = calloc(1, sizeof(*notify));
if (!notify)
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
......@@ -2160,10 +2159,10 @@ void __RPC_USER SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE handle)
void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
return malloc(len);
}
void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
{
HeapFree(GetProcessHeap(), 0, ptr);
free(ptr);
}
......@@ -110,7 +110,6 @@ DWORD RPC_Init(void);
void RPC_Stop(void);
/* from utils.c */
LPWSTR strdupW(LPCWSTR str);
BOOL check_multisz(LPCWSTR lpMultiSz, DWORD cbSize);
......
......@@ -21,6 +21,7 @@
#define WIN32_LEAN_AND_MEAN
#include <stdarg.h>
#include <stdlib.h>
#include <windows.h>
#include <winsvc.h>
......@@ -29,21 +30,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(service);
LPWSTR strdupW(LPCWSTR str)
{
int len;
WCHAR *buf;
if (str == NULL)
return NULL;
len = lstrlenW(str);
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
if (buf == NULL)
return NULL;
lstrcpyW(buf, str);
return buf;
}
BOOL check_multisz(LPCWSTR lpMultiSz, DWORD cbSize)
{
if (cbSize == 0 || (cbSize == sizeof(WCHAR) && lpMultiSz[0] == 0))
......@@ -73,7 +59,7 @@ DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output)
err = ERROR_INVALID_DATATYPE;
goto failed;
}
buf = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
buf = malloc(size + sizeof(WCHAR));
if ((err = RegQueryValueExW(hKey, szValue, 0, &type, (LPBYTE)buf, &size)) != 0)
goto failed;
buf[size/sizeof(WCHAR)] = 0;
......@@ -86,9 +72,9 @@ DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output)
err = GetLastError();
goto failed;
}
str = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
str = malloc(size * sizeof(WCHAR));
ExpandEnvironmentStringsW(buf, str, size);
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
*output = str;
}
else
......@@ -97,7 +83,7 @@ DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output)
failed:
WINE_ERR("Error %ld while reading value %s\n", err, wine_dbgstr_w(szValue));
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
return err;
}
......@@ -112,7 +98,7 @@ DWORD load_reg_multisz(HKEY hKey, LPCWSTR szValue, BOOL bAllowSingle, LPWSTR *ou
{
if (err == ERROR_FILE_NOT_FOUND)
{
*output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR));
*output = calloc(1, sizeof(WCHAR));
return ERROR_SUCCESS;
}
goto failed;
......@@ -122,7 +108,7 @@ DWORD load_reg_multisz(HKEY hKey, LPCWSTR szValue, BOOL bAllowSingle, LPWSTR *ou
err = ERROR_INVALID_DATATYPE;
goto failed;
}
buf = HeapAlloc(GetProcessHeap(), 0, size + 2*sizeof(WCHAR));
buf = malloc(size + 2 * sizeof(WCHAR));
if ((err = RegQueryValueExW(hKey, szValue, 0, &type, (LPBYTE)buf, &size)) != 0)
goto failed;
buf[size/sizeof(WCHAR)] = 0;
......@@ -132,7 +118,7 @@ DWORD load_reg_multisz(HKEY hKey, LPCWSTR szValue, BOOL bAllowSingle, LPWSTR *ou
failed:
WINE_ERR("Error %ld while reading value %s\n", err, wine_dbgstr_w(szValue));
HeapFree(GetProcessHeap(), 0, buf);
free(buf);
return err;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment