Commit c293cd78 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

setupapi: Use CRT functions for memory allocation where possible.

The big win here is getting rid of the reimplementation of wcsdup.
parent 678a8156
......@@ -130,7 +130,7 @@ static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
ofn.hwndOwner = hwnd;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
ofn.lpstrFile = malloc(MAX_PATH * sizeof(WCHAR));
lstrcpyW(ofn.lpstrFile, params->FileSought);
if(GetOpenFileNameW(&ofn))
......@@ -139,7 +139,7 @@ static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
if (last_slash) *last_slash = 0;
SetDlgItemTextW(hwnd, IDC_PATH, ofn.lpstrFile);
}
HeapFree(GetProcessHeap(), 0, ofn.lpstrFile);
free(ofn.lpstrFile);
}
/* Handles the messages sent to the SetupPromptForDisk dialog
......@@ -201,11 +201,11 @@ UINT WINAPI SetupPromptForDiskA(HWND hwndParent, PCSTR DialogTitle, PCSTR DiskNa
ret = SetupPromptForDiskW(hwndParent, DialogTitleW, DiskNameW, PathToSourceW,
FileSoughtW, TagFileW, DiskPromptStyle, PathBufferW, MAX_PATH, PathRequiredSize);
HeapFree(GetProcessHeap(), 0, DialogTitleW);
HeapFree(GetProcessHeap(), 0, DiskNameW);
HeapFree(GetProcessHeap(), 0, PathToSourceW);
HeapFree(GetProcessHeap(), 0, FileSoughtW);
HeapFree(GetProcessHeap(), 0, TagFileW);
free(DialogTitleW);
free(DiskNameW);
free(PathToSourceW);
free(FileSoughtW);
free(TagFileW);
if(ret == DPROMPT_SUCCESS)
{
......
......@@ -72,7 +72,7 @@ static const WCHAR *get_unknown_dirid(void)
if (!unknown_dirid)
{
UINT len = GetSystemDirectoryW( NULL, 0 ) + lstrlenW(L"\\unknown");
if (!(unknown_dirid = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
if (!(unknown_dirid = malloc( len * sizeof(WCHAR) ))) return NULL;
GetSystemDirectoryW( unknown_dirid, len );
lstrcatW( unknown_dirid, L"\\unknown" );
}
......@@ -155,7 +155,7 @@ static const WCHAR *create_system_dirid( int dirid )
return get_unknown_dirid();
}
len = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
if ((str = malloc( len ))) memcpy( str, buffer, len );
return str;
}
......@@ -184,7 +184,7 @@ static const WCHAR *create_printer_dirid( DWORD dirid )
return get_unknown_dirid();
}
len = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
if ((str = malloc( len ))) memcpy( str, buffer, len );
return str;
}
......@@ -199,7 +199,7 @@ static const WCHAR *get_csidl_dir( DWORD csidl )
return get_unknown_dirid();
}
len = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
if ((str = malloc( len ))) memcpy( str, buffer, len );
return str;
}
......@@ -244,22 +244,13 @@ static BOOL store_user_dirid( HINF hinf, int id, WCHAR *str )
for (i = 0; i < nb_user_dirids; i++) if (user_dirids[i].id == id) break;
if (i < nb_user_dirids) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
if (i < nb_user_dirids) free( user_dirids[i].str );
else
{
if (nb_user_dirids >= alloc_user_dirids)
{
int new_size = max( 32, alloc_user_dirids * 2 );
struct user_dirid *new;
if (user_dirids)
new = HeapReAlloc( GetProcessHeap(), 0, user_dirids,
new_size * sizeof(*new) );
else
new = HeapAlloc( GetProcessHeap(), 0,
new_size * sizeof(*new) );
struct user_dirid *new = realloc( user_dirids, new_size * sizeof(*new) );
if (!new) return FALSE;
user_dirids = new;
alloc_user_dirids = new_size;
......@@ -283,7 +274,7 @@ BOOL WINAPI SetupSetDirectoryIdA( HINF hinf, DWORD id, PCSTR dir )
if (!id) /* clear everything */
{
for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
for (i = 0; i < nb_user_dirids; i++) free( user_dirids[i].str );
nb_user_dirids = 0;
return TRUE;
}
......@@ -313,7 +304,7 @@ BOOL WINAPI SetupSetDirectoryIdW( HINF hinf, DWORD id, PCWSTR dir )
if (!id) /* clear everything */
{
for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
for (i = 0; i < nb_user_dirids; i++) free( user_dirids[i].str );
nb_user_dirids = 0;
return TRUE;
}
......@@ -325,7 +316,7 @@ BOOL WINAPI SetupSetDirectoryIdW( HINF hinf, DWORD id, PCWSTR dir )
/* duplicate the string */
len = (lstrlenW(dir)+1) * sizeof(WCHAR);
if (!(str = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
if (!(str = malloc( len ))) return FALSE;
memcpy( str, dir, len );
return store_user_dirid( hinf, id, str );
}
......@@ -66,7 +66,7 @@ HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT
if (rc == 0)
return NULL;
list = HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST));
list = malloc(sizeof(DISKSPACELIST));
list->dwDriveCount = 0;
......@@ -121,7 +121,7 @@ HDSKSPC WINAPI SetupDuplicateDiskSpaceListW(HDSKSPC DiskSpace, PVOID Reserved1,
return NULL;
}
list_copy = HeapAlloc(GetProcessHeap(), 0, sizeof(DISKSPACELIST));
list_copy = malloc(sizeof(DISKSPACELIST));
if (!list_copy)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
......@@ -177,7 +177,7 @@ BOOL WINAPI SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace,
return FALSE;
}
driveW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(DriveSpec) + 2) * sizeof(WCHAR));
driveW = malloc((wcslen(DriveSpec) + 2) * sizeof(WCHAR));
if (!driveW)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
......@@ -200,7 +200,7 @@ BOOL WINAPI SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace,
}
}
HeapFree(GetProcessHeap(), 0, driveW);
free(driveW);
if (!rc) SetLastError(ERROR_INVALID_DRIVE);
return rc;
......@@ -233,7 +233,7 @@ BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
len = MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, NULL, 0);
DriveSpecW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
DriveSpecW = malloc(len * sizeof(WCHAR));
if (!DriveSpecW)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
......@@ -245,7 +245,7 @@ BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
ret = SetupQuerySpaceRequiredOnDriveW(DiskSpace, DriveSpecW, SpaceRequired,
Reserved1, Reserved2);
HeapFree(GetProcessHeap(), 0, DriveSpecW);
free(DriveSpecW);
return ret;
}
......@@ -256,8 +256,8 @@ BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
{
LPDISKSPACELIST list = DiskSpace;
HeapFree(GetProcessHeap(),0,list);
return TRUE;
free(list);
return TRUE;
}
/***********************************************************************
......
......@@ -147,9 +147,7 @@ static BOOL add_handled_dll( const WCHAR *name )
WCHAR **new_dlls;
unsigned int new_count = max( 64, handled_total * 2 );
if (handled_dlls) new_dlls = HeapReAlloc( GetProcessHeap(), 0, handled_dlls,
new_count * sizeof(*handled_dlls) );
else new_dlls = HeapAlloc( GetProcessHeap(), 0, new_count * sizeof(*handled_dlls) );
new_dlls = realloc( handled_dlls, new_count * sizeof(*handled_dlls) );
if (!new_dlls) return FALSE;
handled_dlls = new_dlls;
handled_total = new_count;
......@@ -275,7 +273,7 @@ static BOOL build_fake_dll( HANDLE file, const WCHAR *name )
DWORD size, header_size = lfanew + sizeof(*nt);
info.handle = file;
buffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, header_size + 8 * sizeof(IMAGE_SECTION_HEADER) );
buffer = calloc( 1, header_size + 8 * sizeof(IMAGE_SECTION_HEADER) );
dos = (IMAGE_DOS_HEADER *)buffer;
dos->e_magic = IMAGE_DOS_SIGNATURE;
......@@ -361,7 +359,7 @@ static BOOL build_fake_dll( HANDLE file, const WCHAR *name )
nt->OptionalHeader.SizeOfImage = ALIGN( info.mem_pos, section_alignment );
ret = xwrite( &info, buffer, header_size, 0 );
done:
HeapFree( GetProcessHeap(), 0, buffer );
free( buffer );
return ret;
}
......@@ -387,7 +385,7 @@ static void create_directories( const WCHAR *name )
WCHAR *path, *p;
/* create the directory/directories */
path = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1)*sizeof(WCHAR));
path = malloc((wcslen(name) + 1) * sizeof(WCHAR));
lstrcpyW(path, name);
p = wcschr(path, '\\');
......@@ -399,7 +397,7 @@ static void create_directories( const WCHAR *name )
*p = '\\';
p = wcschr(p+1, '\\');
}
HeapFree(GetProcessHeap(), 0, path);
free(path);
}
static inline WCHAR *prepend( WCHAR *buffer, const WCHAR *str, size_t len )
......@@ -448,7 +446,7 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size )
while ((path = enum_load_path( i++ ))) maxlen = max( maxlen, lstrlenW(path) );
maxlen += ARRAY_SIZE(pe_dir) + len + 1;
if (!(file = HeapAlloc( GetProcessHeap(), 0, maxlen * sizeof(WCHAR) ))) return NULL;
if (!(file = malloc( maxlen * sizeof(WCHAR) ))) return NULL;
pos = maxlen - len - 1;
lstrcpyW( file + pos, name );
......@@ -478,7 +476,7 @@ static void *load_fake_dll( const WCHAR *name, SIZE_T *size )
}
done:
HeapFree( GetProcessHeap(), 0, file );
free( file );
if (res == 1) return data;
return NULL;
}
......@@ -667,7 +665,7 @@ static WCHAR* create_winsxs_dll_path( const xmlstr_t *arch, const xmlstr_t *name
path_len = GetWindowsDirectoryW( NULL, 0 ) + ARRAY_SIZE( L"\\winsxs\\" )
+ arch->len + name->len + key->len + version->len + 19;
path = HeapAlloc( GetProcessHeap(), 0, path_len * sizeof(WCHAR) );
path = malloc( path_len * sizeof(WCHAR) );
GetWindowsDirectoryW( path, path_len );
lstrcatW( path, L"\\winsxs\\" );
append_manifest_filename( arch, name, key, version, lang, path, path_len );
......@@ -686,7 +684,7 @@ static BOOL create_manifest( const xmlstr_t *arch, const xmlstr_t *name, const x
path_len = GetWindowsDirectoryW( NULL, 0 ) + ARRAY_SIZE( L"\\winsxs\\manifests\\" )
+ arch->len + name->len + key->len + version->len + 18 + ARRAY_SIZE( L".manifest" );
path = HeapAlloc( GetProcessHeap(), 0, path_len * sizeof(WCHAR) );
path = malloc( path_len * sizeof(WCHAR) );
GetWindowsDirectoryW( path, path_len );
lstrcatW( path, L"\\winsxs\\manifests\\" );
append_manifest_filename( arch, name, key, version, lang, path, path_len );
......@@ -706,7 +704,7 @@ static BOOL create_manifest( const xmlstr_t *arch, const xmlstr_t *name, const x
CloseHandle( handle );
if (!ret) DeleteFileW( path );
}
HeapFree( GetProcessHeap(), 0, path );
free( path );
return ret;
}
......@@ -764,9 +762,8 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
if (!error && dest && name.ptr)
{
struct delay_copy *add = HeapAlloc( GetProcessHeap(), 0,
sizeof(*add) + (dll_data->src_len + name.len +
dest_len + name.len + 1) * sizeof(WCHAR) );
struct delay_copy *add = malloc( sizeof(*add) +
(dll_data->src_len + name.len + dest_len + name.len + 1) * sizeof(WCHAR) );
add->src = add->data;
memcpy( add->src, dll_data->src_dir, dll_data->src_len * sizeof(WCHAR) );
MultiByteToWideChar( CP_UTF8, 0, name.ptr, name.len,
......@@ -783,7 +780,7 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
}
if (!xmlstr_cmp( &elem, "assemblyIdentity" )) continue;
HeapFree( GetProcessHeap(), 0, dest );
free( dest );
dest = NULL;
while (next_xml_attr( &buffer, &attr_name, &attr_value, &error ))
{
......@@ -802,7 +799,7 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
}
if (!arch.len) /* fixup the architecture */
{
char *new_buffer = HeapAlloc( GetProcessHeap(), 0, len + sizeof(current_arch) );
char *new_buffer = malloc( len + sizeof(current_arch) );
memcpy( new_buffer, manifest, arch.ptr - manifest );
strcpy( new_buffer + (arch.ptr - manifest), current_arch );
memcpy( new_buffer + strlen(new_buffer), arch.ptr, len - (arch.ptr - manifest) );
......@@ -810,7 +807,7 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
arch.len = strlen( current_arch );
dest = create_winsxs_dll_path( &arch, &name, &key, &version, &lang );
create_manifest( &arch, &name, &key, &version, &lang, new_buffer, len + arch.len );
HeapFree( GetProcessHeap(), 0, new_buffer );
free( new_buffer );
}
else
{
......@@ -820,7 +817,7 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
dest_len = wcslen( dest );
}
}
HeapFree( GetProcessHeap(), 0, dest );
free( dest );
return TRUE;
}
......@@ -835,11 +832,11 @@ static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR nam
if (!str) return FALSE;
lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE;
if (!(buffer = malloc( lenW * sizeof(WCHAR) ))) return FALSE;
MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
buffer[lenW - 1] = 0;
*hr = IRegistrar_StringRegister( registrar, buffer );
HeapFree( GetProcessHeap(), 0, buffer );
free( buffer );
return TRUE;
}
......@@ -945,7 +942,7 @@ static void delay_copy_files( struct list *delay_copy )
ret = read_file( copy->src, &data, &size );
if (ret != 1)
{
HeapFree( GetProcessHeap(), 0, copy );
free( copy );
continue;
}
......@@ -957,7 +954,7 @@ static void delay_copy_files( struct list *delay_copy )
CloseHandle( h );
if (!ret) DeleteFileW( copy->dest );
}
HeapFree( GetProcessHeap(), 0, copy );
free( copy );
}
}
......@@ -1012,11 +1009,11 @@ static BOOL create_wildcard_dlls( const WCHAR *dirname, const WCHAR *wildcard, B
if (build_dir) maxlen = lstrlenW(build_dir) + ARRAY_SIZE(L"\\programs") + 1;
for (i = 0; (path = enum_load_path(i)); i++) maxlen = max( maxlen, lstrlenW(path) );
maxlen += 2 * max_dll_name_len + 2 + ARRAY_SIZE(pe_dir) + 10; /* ".dll" */
if (!(file = HeapAlloc( GetProcessHeap(), 0, maxlen * sizeof(WCHAR) ))) return FALSE;
if (!(file = malloc( maxlen * sizeof(WCHAR) ))) return FALSE;
if (!(dest = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(dirname) + max_dll_name_len) * sizeof(WCHAR) )))
if (!(dest = malloc( (wcslen(dirname) + max_dll_name_len) * sizeof(WCHAR) )))
{
HeapFree( GetProcessHeap(), 0, file );
free( file );
return FALSE;
}
lstrcpyW( dest, dirname );
......@@ -1038,8 +1035,8 @@ static BOOL create_wildcard_dlls( const WCHAR *dirname, const WCHAR *wildcard, B
lstrcpyW( file, path );
install_lib_dir( dest, file, wildcard, NULL, delete );
}
HeapFree( GetProcessHeap(), 0, file );
HeapFree( GetProcessHeap(), 0, dest );
free( file );
free( dest );
return TRUE;
}
......@@ -1101,7 +1098,7 @@ void cleanup_fake_dlls(void)
{
if (file_buffer) VirtualFree( file_buffer, 0, MEM_RELEASE );
file_buffer = NULL;
HeapFree( GetProcessHeap(), 0, handled_dlls );
free( handled_dlls );
handled_dlls = NULL;
handled_count = handled_total = 0;
if (registrar) IRegistrar_Release( registrar );
......
......@@ -67,7 +67,7 @@ static CRITICAL_SECTION setupapi_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
*/
VOID WINAPI MyFree(LPVOID lpMem)
{
HeapFree(GetProcessHeap(), 0, lpMem);
free(lpMem);
}
......@@ -85,7 +85,7 @@ VOID WINAPI MyFree(LPVOID lpMem)
*/
LPVOID WINAPI MyMalloc(DWORD dwSize)
{
return HeapAlloc(GetProcessHeap(), 0, dwSize);
return malloc(dwSize);
}
......@@ -109,10 +109,7 @@ LPVOID WINAPI MyMalloc(DWORD dwSize)
*/
LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize)
{
if (lpSrc == NULL)
return HeapAlloc(GetProcessHeap(), 0, dwSize);
return HeapReAlloc(GetProcessHeap(), 0, lpSrc, dwSize);
return realloc(lpSrc, dwSize);
}
......@@ -872,8 +869,8 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location,
done:
MyFree( destW );
HeapFree( GetProcessHeap(), 0, sourceW );
HeapFree( GetProcessHeap(), 0, locationW );
free( sourceW );
free( locationW );
if (ret) SetLastError(ERROR_SUCCESS);
return ret;
}
......@@ -1121,7 +1118,7 @@ BOOL WINAPI SetupUninstallOEMInfA( PCSTR inf_file, DWORD flags, PVOID reserved )
if (inf_file && !(inf_fileW = strdupAtoW( inf_file ))) return FALSE;
ret = SetupUninstallOEMInfW( inf_fileW, flags, reserved );
HeapFree( GetProcessHeap(), 0, inf_fileW );
free( inf_fileW );
return ret;
}
......@@ -1325,7 +1322,7 @@ BOOL WINAPI SetupGetFileCompressionInfoExA( PCSTR source, PSTR name, DWORD len,
if (name)
{
ret = SetupGetFileCompressionInfoExW( sourceW, NULL, 0, &nb_chars, NULL, NULL, NULL );
if (!(nameW = HeapAlloc( GetProcessHeap(), 0, nb_chars * sizeof(WCHAR) )))
if (!(nameW = malloc( nb_chars * sizeof(WCHAR) )))
{
MyFree( sourceW );
return FALSE;
......@@ -1346,7 +1343,7 @@ BOOL WINAPI SetupGetFileCompressionInfoExA( PCSTR source, PSTR name, DWORD len,
}
}
if (required) *required = nb_chars;
HeapFree( GetProcessHeap(), 0, nameW );
free( nameW );
MyFree( sourceW );
return ret;
......@@ -1776,7 +1773,7 @@ BOOL WINAPI SetupLogErrorW(LPCWSTR message, LogSeverity severity)
if (message)
{
len = WideCharToMultiByte(CP_ACP, 0, message, -1, NULL, 0, NULL, NULL);
msg = HeapAlloc(GetProcessHeap(), 0, len);
msg = malloc(len);
if (msg == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
......@@ -1790,7 +1787,7 @@ BOOL WINAPI SetupLogErrorW(LPCWSTR message, LogSeverity severity)
*/
ret = SetupLogErrorA(msg, severity);
HeapFree(GetProcessHeap(), 0, msg);
free(msg);
return ret;
}
......
......@@ -158,15 +158,12 @@ static void *grow_array( void *array, unsigned int *count, size_t elem )
unsigned int new_count = *count + *count / 2;
if (new_count < 32) new_count = 32;
if (array)
new_array = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, array, new_count * elem );
else
new_array = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, new_count * elem );
new_array = _recalloc( array, new_count, elem );
if (new_array)
*count = new_count;
else
HeapFree( GetProcessHeap(), 0, array );
free( array );
return new_array;
}
......@@ -219,7 +216,7 @@ static int add_section( struct inf_file *file, const WCHAR *name )
if (!(file->sections = grow_array( file->sections, &file->alloc_sections,
sizeof(file->sections[0]) ))) return -1;
}
if (!(section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) ))) return -1;
if (!(section = malloc( sizeof(*section) ))) return -1;
section->name = name;
section->nb_lines = 0;
section->alloc_lines = ARRAY_SIZE( section->lines );
......@@ -240,7 +237,7 @@ static struct line *add_line( struct inf_file *file, int section_index )
if (section->nb_lines == section->alloc_lines) /* need to grow the section */
{
int size = sizeof(*section) - sizeof(section->lines) + 2*section->alloc_lines*sizeof(*line);
if (!(section = HeapReAlloc( GetProcessHeap(), 0, section, size ))) return NULL;
if (!(section = realloc( section, size ))) return NULL;
section->alloc_lines *= 2;
file->sections[section_index] = section;
}
......@@ -345,14 +342,14 @@ static const WCHAR *get_string_subst( const struct inf_file *file, const WCHAR *
return field->text;
not_found: /* check for integer id */
if ((dirid_str = HeapAlloc( GetProcessHeap(), 0, (*len+1) * sizeof(WCHAR) )))
if ((dirid_str = malloc( (*len + 1) * sizeof(WCHAR) )))
{
memcpy( dirid_str, str, *len * sizeof(WCHAR) );
dirid_str[*len] = 0;
dirid = wcstol( dirid_str, &end, 10 );
if (!*end) ret = get_dirid_subst( file, dirid, len );
if (no_trailing_slash && ret && *len && ret[*len - 1] == '\\') *len -= 1;
HeapFree( GetProcessHeap(), 0, dirid_str );
free( dirid_str );
return ret;
}
return NULL;
......@@ -860,12 +857,12 @@ static void free_inf_file( struct inf_file *file )
{
unsigned int i;
for (i = 0; i < file->nb_sections; i++) HeapFree( GetProcessHeap(), 0, file->sections[i] );
HeapFree( GetProcessHeap(), 0, file->filename );
HeapFree( GetProcessHeap(), 0, file->sections );
HeapFree( GetProcessHeap(), 0, file->fields );
for (i = 0; i < file->nb_sections; i++) free( file->sections[i] );
free( file->filename );
free( file->sections );
free( file->fields );
HeapFree( GetProcessHeap(), 0, file->strings );
HeapFree( GetProcessHeap(), 0, file );
free( file );
}
......@@ -896,14 +893,12 @@ static DWORD parse_buffer( struct inf_file *file, const WCHAR *buffer, const WCH
/* trim excess buffer space */
if (file->alloc_sections > file->nb_sections)
{
file->sections = HeapReAlloc( GetProcessHeap(), 0, file->sections,
file->nb_sections * sizeof(file->sections[0]) );
file->sections = realloc( file->sections, file->nb_sections * sizeof(file->sections[0]) );
file->alloc_sections = file->nb_sections;
}
if (file->alloc_fields > file->nb_fields)
{
file->fields = HeapReAlloc( GetProcessHeap(), 0, file->fields,
file->nb_fields * sizeof(file->fields[0]) );
file->fields = realloc( file->fields, file->nb_fields * sizeof(file->fields[0]) );
file->alloc_fields = file->nb_fields;
}
file->strings = HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, file->strings,
......@@ -963,7 +958,7 @@ static struct inf_file *parse_file( HANDLE handle, const WCHAR *class, DWORD sty
if (class) FIXME( "class %s not supported yet\n", debugstr_w(class) );
if (!(file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*file) )))
if (!(file = calloc( 1, sizeof(*file) )))
{
err = ERROR_NOT_ENOUGH_MEMORY;
goto done;
......@@ -993,12 +988,12 @@ static struct inf_file *parse_file( HANDLE handle, const WCHAR *class, DWORD sty
offset = sizeof(utf8_bom);
}
if ((new_buff = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) )))
if ((new_buff = malloc( size * sizeof(WCHAR) )))
{
DWORD len = MultiByteToWideChar( codepage, 0, (char *)buffer + offset,
size - offset, new_buff, size );
err = parse_buffer( file, new_buff, new_buff + len, error_line );
HeapFree( GetProcessHeap(), 0, new_buff );
free( new_buff );
}
}
else
......@@ -1068,7 +1063,7 @@ WCHAR *PARSER_get_dest_dir( INFCONTEXT *context )
if (!SetupGetIntField( context, 1, &dirid )) return NULL;
if (!(dir = get_dirid_subst( context->Inf, dirid, &len1 ))) return NULL;
if (!SetupGetStringFieldW( context, 2, NULL, 0, &len2 )) len2 = 0;
if (!(ret = HeapAlloc( GetProcessHeap(), 0, (len1+len2+1) * sizeof(WCHAR) ))) return NULL;
if (!(ret = malloc( (len1 + len2 + 1) * sizeof(WCHAR) ))) return NULL;
memcpy( ret, dir, len1 * sizeof(WCHAR) );
ptr = ret + len1;
if (len2 && ptr > ret && ptr[-1] != '\\') *ptr++ = '\\';
......@@ -1114,7 +1109,7 @@ HINF WINAPI SetupOpenInfFileW( PCWSTR name, PCWSTR class, DWORD style, UINT *err
if (wcschr( name, '\\' ) || wcschr( name, '/' ))
{
if (!(len = GetFullPathNameW( name, 0, NULL, NULL ))) return INVALID_HANDLE_VALUE;
if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
if (!(path = malloc( len * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return INVALID_HANDLE_VALUE;
......@@ -1128,7 +1123,7 @@ HINF WINAPI SetupOpenInfFileW( PCWSTR name, PCWSTR class, DWORD style, UINT *err
static const WCHAR System32[] = {'\\','s','y','s','t','e','m','3','2','\\',0};
len = GetWindowsDirectoryW( NULL, 0 ) + lstrlenW(name) + 12;
if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
if (!(path = malloc( len * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return INVALID_HANDLE_VALUE;
......@@ -1153,7 +1148,7 @@ HINF WINAPI SetupOpenInfFileW( PCWSTR name, PCWSTR class, DWORD style, UINT *err
}
if (!file)
{
HeapFree( GetProcessHeap(), 0, path );
free( path );
return INVALID_HANDLE_VALUE;
}
TRACE( "%s -> %p\n", debugstr_w(path), file );
......@@ -1781,7 +1776,7 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result )
if (!(ret = SetupGetStringFieldA( context, index, localbuff, sizeof(localbuff), &required )))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required ))) return FALSE;
if (!(buffer = malloc( required ))) return FALSE;
if (!(ret = SetupGetStringFieldA( context, index, buffer, required, NULL ))) goto done;
}
/* The call to SetupGetStringFieldA succeeded. If buffer is empty we have an optional field */
......@@ -1798,7 +1793,7 @@ BOOL WINAPI SetupGetIntField( PINFCONTEXT context, DWORD index, PINT result )
}
done:
if (buffer != localbuff) HeapFree( GetProcessHeap(), 0, buffer );
if (buffer != localbuff) free( buffer );
return ret;
}
......
......@@ -136,7 +136,7 @@ BOOL WINAPI SetupGetInfInformationA(LPCVOID InfSpec, DWORD SearchControl,
if (InfSpec && SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
{
len = MultiByteToWideChar(CP_ACP, 0, InfSpec, -1, NULL, 0);
inf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
inf = malloc(len * sizeof(WCHAR));
if (!inf)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
......@@ -149,7 +149,7 @@ BOOL WINAPI SetupGetInfInformationA(LPCVOID InfSpec, DWORD SearchControl,
ReturnBufferSize, RequiredSize);
if (SearchControl >= INFINFO_INF_NAME_IS_ABSOLUTE)
HeapFree(GetProcessHeap(), 0, inf);
free(inf);
return ret;
}
......@@ -241,13 +241,13 @@ BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
if (!ret)
return FALSE;
filenameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
filenameW = malloc(size * sizeof(WCHAR));
ret = SetupQueryInfFileInformationW(InfInformation, InfIndex,
filenameW, size, &size);
if (!ret)
{
HeapFree(GetProcessHeap(), 0, filenameW);
free(filenameW);
return FALSE;
}
......@@ -256,7 +256,7 @@ BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
if (!ReturnBuffer)
{
HeapFree(GetProcessHeap(), 0, filenameW);
free(filenameW);
if (ReturnBufferSize)
{
SetLastError(ERROR_INVALID_PARAMETER);
......@@ -268,13 +268,13 @@ BOOL WINAPI SetupQueryInfFileInformationA(PSP_INF_INFORMATION InfInformation,
if (size > ReturnBufferSize)
{
HeapFree(GetProcessHeap(), 0, filenameW);
free(filenameW);
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
WideCharToMultiByte(CP_ACP, 0, filenameW, -1, ReturnBuffer, size, NULL, NULL);
HeapFree(GetProcessHeap(), 0, filenameW);
free(filenameW);
return ret;
}
......@@ -342,7 +342,7 @@ BOOL WINAPI SetupGetSourceFileLocationA( HINF hinf, PINFCONTEXT context, PCSTR f
if (!SetupGetSourceFileLocationW( hinf, context, filenameW, source_id, NULL, 0, &required ))
goto done;
if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, required * sizeof(WCHAR) )))
if (!(bufferW = malloc( required * sizeof(WCHAR) )))
goto done;
if (!SetupGetSourceFileLocationW( hinf, context, filenameW, source_id, bufferW, required, NULL ))
......@@ -364,8 +364,8 @@ BOOL WINAPI SetupGetSourceFileLocationA( HINF hinf, PINFCONTEXT context, PCSTR f
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, filenameW );
HeapFree( GetProcessHeap(), 0, bufferW );
free( filenameW );
free( bufferW );
return ret;
}
......@@ -381,19 +381,19 @@ static LPWSTR get_source_id( HINF hinf, PINFCONTEXT context, PCWSTR filename )
if (!SetupGetStringFieldW( context, 1, NULL, 0, &size ))
return NULL;
if (!(source_id = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) )))
if (!(source_id = malloc( size * sizeof(WCHAR) )))
return NULL;
if (!SetupGetStringFieldW( context, 1, source_id, size, NULL ))
{
HeapFree( GetProcessHeap(), 0, source_id );
free( source_id );
return NULL;
}
if (!SetupFindFirstLineW( hinf, source_disks_names_platform, source_id, context ) &&
!SetupFindFirstLineW( hinf, source_disks_names, source_id, context ))
{
HeapFree( GetProcessHeap(), 0, source_id );
free( source_id );
return NULL;
}
return source_id;
......@@ -421,10 +421,10 @@ BOOL WINAPI SetupGetSourceFileLocationW( HINF hinf, PINFCONTEXT context, PCWSTR
*source_id = wcstol( source_id_str, &end, 10 );
if (end == source_id_str || *end)
{
HeapFree( GetProcessHeap(), 0, source_id_str );
free( source_id_str );
return FALSE;
}
HeapFree( GetProcessHeap(), 0, source_id_str );
free( source_id_str );
if (SetupGetStringFieldW( context, 4, buffer, buffer_size, required_size ))
return TRUE;
......@@ -460,7 +460,7 @@ BOOL WINAPI SetupGetSourceInfoA( HINF hinf, UINT source_id, UINT info,
if (!SetupGetSourceInfoW( hinf, source_id, info, NULL, 0, &required ))
return FALSE;
if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, required * sizeof(WCHAR) )))
if (!(bufferW = malloc( required * sizeof(WCHAR) )))
return FALSE;
if (!SetupGetSourceInfoW( hinf, source_id, info, bufferW, required, NULL ))
......@@ -482,7 +482,7 @@ BOOL WINAPI SetupGetSourceInfoA( HINF hinf, UINT source_id, UINT info,
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, bufferW );
free( bufferW );
return ret;
}
......@@ -554,7 +554,7 @@ BOOL WINAPI SetupGetTargetPathA( HINF hinf, PINFCONTEXT context, PCSTR section,
if (!SetupGetTargetPathW( hinf, context, sectionW, NULL, 0, &required ))
goto done;
if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, required * sizeof(WCHAR) )))
if (!(bufferW = malloc( required * sizeof(WCHAR) )))
goto done;
if (!SetupGetTargetPathW( hinf, context, sectionW, bufferW, required, NULL ))
......@@ -576,8 +576,8 @@ BOOL WINAPI SetupGetTargetPathA( HINF hinf, PINFCONTEXT context, PCSTR section,
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, sectionW );
HeapFree( GetProcessHeap(), 0, bufferW );
free( sectionW );
free( bufferW );
return ret;
}
......@@ -622,11 +622,11 @@ BOOL WINAPI SetupGetTargetPathW( HINF hinf, PINFCONTEXT context, PCWSTR section,
else
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
if (dir != systemdir) HeapFree( GetProcessHeap(), 0, dir );
if (dir != systemdir) free( dir );
return FALSE;
}
}
if (dir != systemdir) HeapFree( GetProcessHeap(), 0, dir );
if (dir != systemdir) free( dir );
return TRUE;
}
......
......@@ -47,29 +47,13 @@
extern HINSTANCE SETUPAPI_hInstance DECLSPEC_HIDDEN;
static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
}
static inline WCHAR *strdupW( const WCHAR *str )
{
WCHAR *ret = NULL;
if (str)
{
int len = (lstrlenW(str) + 1) * sizeof(WCHAR);
if ((ret = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( ret, str, len );
}
return ret;
}
static inline char *strdupWtoA( const WCHAR *str )
{
char *ret = NULL;
if (str)
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
if ((ret = malloc( len )))
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
}
return ret;
......@@ -81,7 +65,7 @@ static inline WCHAR *strdupAtoW( const char *str )
if (str)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
if ((ret = malloc( len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
}
return ret;
......
......@@ -53,12 +53,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
static void * CDECL sc_cb_alloc(ULONG cb)
{
return HeapAlloc(GetProcessHeap(), 0, cb);
return malloc(cb);
}
static void CDECL sc_cb_free(void *pv)
{
HeapFree(GetProcessHeap(), 0, pv);
free(pv);
}
static INT_PTR CDECL sc_cb_open(char *pszFile, int oflag, int pmode)
......
......@@ -399,7 +399,7 @@ DWORD WINAPI StringTableAddStringEx(HSTRING_TABLE hTable, LPWSTR string,
len = sizeof(DWORD) + (lstrlenW(string)+1)*sizeof(WCHAR) + table->max_extra_size;
if (table->nextoffset + len >= table->allocated) {
table->allocated <<= 1;
table->data = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, table->data, table->allocated);
table->data = _recalloc(table->data, 1, table->allocated);
}
/* hash string */
......
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