1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-05 17:28:47 +00:00

mountmgr: Use standard C functions for memory allocation.

This commit is contained in:
Alex Henrie 2022-11-29 18:11:30 -07:00 committed by Alexandre Julliard
parent 9dba420d0a
commit 61dc7de497
2 changed files with 42 additions and 60 deletions

View File

@ -113,24 +113,6 @@ static CRITICAL_SECTION_DEBUG critsect_debug =
}; };
static CRITICAL_SECTION device_section = { &critsect_debug, -1, 0, 0, 0, 0 }; static CRITICAL_SECTION device_section = { &critsect_debug, -1, 0, 0, 0, 0 };
static char *strdupA( const char *str )
{
char *ret;
if (!str) return NULL;
if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
return ret;
}
static WCHAR *strdupW( const WCHAR *str )
{
WCHAR *ret;
if (!str) return NULL;
if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, (lstrlenW(str) + 1) * sizeof(WCHAR) ))) lstrcpyW( ret, str );
return ret;
}
static const GUID *get_default_uuid( int letter ) static const GUID *get_default_uuid( int letter )
{ {
static GUID guid; static GUID guid;
@ -649,7 +631,7 @@ static NTSTATUS create_disk_device( enum device_type type, struct disk_device **
} }
name.MaximumLength = (lstrlenW(format) + 10) * sizeof(WCHAR); name.MaximumLength = (lstrlenW(format) + 10) * sizeof(WCHAR);
name.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, name.MaximumLength ); name.Buffer = malloc( name.MaximumLength );
for (i = first; i < 32; i++) for (i = first; i < 32; i++)
{ {
swprintf( name.Buffer, name.MaximumLength / sizeof(WCHAR), format, i ); swprintf( name.Buffer, name.MaximumLength / sizeof(WCHAR), format, i );
@ -673,7 +655,7 @@ static NTSTATUS create_disk_device( enum device_type type, struct disk_device **
UNICODE_STRING symlink; UNICODE_STRING symlink;
symlink.MaximumLength = (lstrlenW(link_format) + 10) * sizeof(WCHAR); symlink.MaximumLength = (lstrlenW(link_format) + 10) * sizeof(WCHAR);
if ((symlink.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, symlink.MaximumLength))) if ((symlink.Buffer = malloc( symlink.MaximumLength )))
{ {
swprintf( symlink.Buffer, symlink.MaximumLength / sizeof(WCHAR), link_format, i ); swprintf( symlink.Buffer, symlink.MaximumLength / sizeof(WCHAR), link_format, i );
symlink.Length = lstrlenW(symlink.Buffer) * sizeof(WCHAR); symlink.Length = lstrlenW(symlink.Buffer) * sizeof(WCHAR);
@ -732,9 +714,9 @@ static void delete_disk_device( struct disk_device *device )
IoDeleteSymbolicLink( &device->symlink ); IoDeleteSymbolicLink( &device->symlink );
RtlFreeUnicodeString( &device->symlink ); RtlFreeUnicodeString( &device->symlink );
} }
RtlFreeHeap( GetProcessHeap(), 0, device->unix_device ); free( device->unix_device );
RtlFreeHeap( GetProcessHeap(), 0, device->unix_mount ); free( device->unix_mount );
RtlFreeHeap( GetProcessHeap(), 0, device->serial ); free( device->serial );
RtlFreeUnicodeString( &device->name ); RtlFreeUnicodeString( &device->name );
IoDeleteDevice( device->dev_obj ); IoDeleteDevice( device->dev_obj );
} }
@ -758,7 +740,7 @@ static unsigned int release_volume( struct volume *volume )
list_remove( &volume->entry ); list_remove( &volume->entry );
if (volume->mount) delete_mount_point( volume->mount ); if (volume->mount) delete_mount_point( volume->mount );
delete_disk_device( volume->device ); delete_disk_device( volume->device );
RtlFreeHeap( GetProcessHeap(), 0, volume ); free( volume );
} }
return ret; return ret;
} }
@ -770,11 +752,11 @@ static void set_volume_udi( struct volume *volume, const char *udi )
{ {
assert( !volume->udi ); assert( !volume->udi );
/* having a udi means the HAL side holds an extra reference */ /* having a udi means the HAL side holds an extra reference */
if ((volume->udi = strdupA( udi ))) grab_volume( volume ); if ((volume->udi = strdup( udi ))) grab_volume( volume );
} }
else if (volume->udi) else if (volume->udi)
{ {
RtlFreeHeap( GetProcessHeap(), 0, volume->udi ); free( volume->udi );
volume->udi = NULL; volume->udi = NULL;
release_volume( volume ); release_volume( volume );
} }
@ -786,7 +768,7 @@ static NTSTATUS create_volume( const char *udi, enum device_type type, struct vo
struct volume *volume; struct volume *volume;
NTSTATUS status; NTSTATUS status;
if (!(volume = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*volume) ))) if (!(volume = calloc( 1, sizeof(*volume) )))
return STATUS_NO_MEMORY; return STATUS_NO_MEMORY;
if (!(status = create_disk_device( type, &volume->device, volume ))) if (!(status = create_disk_device( type, &volume->device, volume )))
@ -795,7 +777,7 @@ static NTSTATUS create_volume( const char *udi, enum device_type type, struct vo
list_add_tail( &volumes_list, &volume->entry ); list_add_tail( &volumes_list, &volume->entry );
*volume_ret = grab_volume( volume ); *volume_ret = grab_volume( volume );
} }
else RtlFreeHeap( GetProcessHeap(), 0, volume ); else free( volume );
return status; return status;
} }
@ -807,7 +789,7 @@ static NTSTATUS create_dos_device( struct volume *volume, const char *udi, int l
struct dos_drive *drive; struct dos_drive *drive;
NTSTATUS status; NTSTATUS status;
if (!(drive = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*drive) ))) return STATUS_NO_MEMORY; if (!(drive = malloc( sizeof(*drive) ))) return STATUS_NO_MEMORY;
drive->drive = letter; drive->drive = letter;
drive->mount = NULL; drive->mount = NULL;
@ -824,7 +806,7 @@ static NTSTATUS create_dos_device( struct volume *volume, const char *udi, int l
list_add_tail( &drives_list, &drive->entry ); list_add_tail( &drives_list, &drive->entry );
*drive_ret = drive; *drive_ret = drive;
} }
else RtlFreeHeap( GetProcessHeap(), 0, drive ); else free( drive );
return status; return status;
} }
@ -835,7 +817,7 @@ static void delete_dos_device( struct dos_drive *drive )
list_remove( &drive->entry ); list_remove( &drive->entry );
if (drive->mount) delete_mount_point( drive->mount ); if (drive->mount) delete_mount_point( drive->mount );
release_volume( drive->volume ); release_volume( drive->volume );
RtlFreeHeap( GetProcessHeap(), 0, drive ); free( drive );
} }
/* find a volume that matches the parameters */ /* find a volume that matches the parameters */
@ -952,8 +934,8 @@ static void set_dos_devices_disk_serial( struct disk_device *device )
/* copy serial if drive resides on this Unix device */ /* copy serial if drive resides on this Unix device */
if (devices & (1 << drive->drive)) if (devices & (1 << drive->drive))
{ {
HeapFree( GetProcessHeap(), 0, drive->volume->device->serial ); free( drive->volume->device->serial );
drive->volume->device->serial = strdupA( device->serial ); drive->volume->device->serial = strdup( device->serial );
} }
} }
} }
@ -986,13 +968,13 @@ static NTSTATUS set_volume_info( struct volume *volume, struct dos_drive *drive,
} }
else else
{ {
RtlFreeHeap( GetProcessHeap(), 0, disk_device->unix_device ); free( disk_device->unix_device );
RtlFreeHeap( GetProcessHeap(), 0, disk_device->unix_mount ); free( disk_device->unix_mount );
RtlFreeHeap( GetProcessHeap(), 0, disk_device->serial ); free( disk_device->serial );
} }
disk_device->unix_device = strdupA( device ); disk_device->unix_device = strdup( device );
disk_device->unix_mount = strdupA( mount_point ); disk_device->unix_mount = strdup( mount_point );
disk_device->serial = strdupA( disk_serial ); disk_device->serial = strdup( disk_serial );
set_dos_devices_disk_serial( disk_device ); set_dos_devices_disk_serial( disk_device );
if (!get_volume_device_info( volume )) if (!get_volume_device_info( volume ))
@ -1467,9 +1449,9 @@ NTSTATUS query_unix_drive( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_
device_type = volume->device->type; device_type = volume->device->type;
fs_type = get_mountmgr_fs_type( volume->fs_type ); fs_type = get_mountmgr_fs_type( volume->fs_type );
serial = volume->serial; serial = volume->serial;
device = strdupA( volume->device->unix_device ); device = strdup( volume->device->unix_device );
mount_point = strdupA( volume->device->unix_mount ); mount_point = strdup( volume->device->unix_mount );
label = strdupW( volume->label ); label = wcsdup( volume->label );
release_volume( volume ); release_volume( volume );
} }
LeaveCriticalSection( &device_section ); LeaveCriticalSection( &device_section );
@ -1532,9 +1514,9 @@ NTSTATUS query_unix_drive( void *buff, SIZE_T insize, SIZE_T outsize, IO_STATUS_
iosb->Information = ptr - (char *)output; iosb->Information = ptr - (char *)output;
if (size > outsize) status = STATUS_BUFFER_OVERFLOW; if (size > outsize) status = STATUS_BUFFER_OVERFLOW;
RtlFreeHeap( GetProcessHeap(), 0, device ); free( device );
RtlFreeHeap( GetProcessHeap(), 0, mount_point ); free( mount_point );
RtlFreeHeap( GetProcessHeap(), 0, label ); free( label );
return status; return status;
} }

View File

@ -48,9 +48,9 @@ static HKEY mount_key;
void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len ) void set_mount_point_id( struct mount_point *mount, const void *id, unsigned int id_len )
{ {
RtlFreeHeap( GetProcessHeap(), 0, mount->id ); free( mount->id );
mount->id_len = max( MIN_ID_LEN, id_len ); mount->id_len = max( MIN_ID_LEN, id_len );
if ((mount->id = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, mount->id_len ))) if ((mount->id = calloc( mount->id_len, 1 )))
{ {
memcpy( mount->id, id, id_len ); memcpy( mount->id, id, id_len );
RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len ); RegSetValueExW( mount_key, mount->link.Buffer, 0, REG_BINARY, mount->id, mount->id_len );
@ -65,7 +65,7 @@ static struct mount_point *add_mount_point( DEVICE_OBJECT *device, UNICODE_STRIN
WCHAR *str; WCHAR *str;
UINT len = (lstrlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR); UINT len = (lstrlenW(link) + 1) * sizeof(WCHAR) + device_name->Length + sizeof(WCHAR);
if (!(mount = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*mount) + len ))) return NULL; if (!(mount = malloc( sizeof(*mount) + len ))) return NULL;
str = (WCHAR *)(mount + 1); str = (WCHAR *)(mount + 1);
lstrcpyW( str, link ); lstrcpyW( str, link );
@ -116,8 +116,8 @@ void delete_mount_point( struct mount_point *mount )
list_remove( &mount->entry ); list_remove( &mount->entry );
RegDeleteValueW( mount_key, mount->link.Buffer ); RegDeleteValueW( mount_key, mount->link.Buffer );
IoDeleteSymbolicLink( &mount->link ); IoDeleteSymbolicLink( &mount->link );
RtlFreeHeap( GetProcessHeap(), 0, mount->id ); free( mount->id );
RtlFreeHeap( GetProcessHeap(), 0, mount ); free( mount );
} }
/* check if a given mount point matches the requested specs */ /* check if a given mount point matches the requested specs */
@ -186,7 +186,7 @@ static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
return STATUS_BUFFER_OVERFLOW; return STATUS_BUFFER_OVERFLOW;
} }
input = HeapAlloc( GetProcessHeap(), 0, insize ); input = malloc( insize );
if (!input) if (!input)
return STATUS_NO_MEMORY; return STATUS_NO_MEMORY;
memcpy( input, buff, insize ); memcpy( input, buff, insize );
@ -217,7 +217,7 @@ static NTSTATUS query_mount_points( void *buff, SIZE_T insize,
} }
info->Size = pos; info->Size = pos;
iosb->Information = pos; iosb->Information = pos;
HeapFree( GetProcessHeap(), 0, input ); free( input );
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -298,7 +298,7 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
for (;;) for (;;)
{ {
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) if (!(buffer = malloc( size )))
{ {
status = STATUS_NO_MEMORY; status = STATUS_NO_MEMORY;
goto done; goto done;
@ -307,12 +307,12 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
if (status == STATUS_NO_SUCH_FILE) status = STATUS_SUCCESS; if (status == STATUS_NO_SUCH_FILE) status = STATUS_SUCCESS;
if (status == STATUS_SUCCESS) break; if (status == STATUS_SUCCESS) break;
if (status != STATUS_BUFFER_TOO_SMALL) goto done; if (status != STATUS_BUFFER_TOO_SMALL) goto done;
HeapFree( GetProcessHeap(), 0, buffer ); free( buffer );
} }
if (input->create_backup) if (input->create_backup)
{ {
if (!(backup = HeapAlloc( GetProcessHeap(), 0, strlen(buffer) + sizeof(".backup" ) ))) if (!(backup = malloc( strlen(buffer) + sizeof(".backup" ) )))
{ {
status = STATUS_NO_MEMORY; status = STATUS_NO_MEMORY;
goto done; goto done;
@ -327,8 +327,8 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
status = MOUNTMGR_CALL( set_shell_folder, &params ); status = MOUNTMGR_CALL( set_shell_folder, &params );
done: done:
HeapFree( GetProcessHeap(), 0, buffer ); free( buffer );
HeapFree( GetProcessHeap(), 0, backup ); free( backup );
return status; return status;
} }
@ -348,7 +348,7 @@ static NTSTATUS query_shell_folder( void *buff, SIZE_T insize, SIZE_T outsize, I
for (;;) for (;;)
{ {
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) return STATUS_NO_MEMORY; if (!(buffer = malloc( size ))) return STATUS_NO_MEMORY;
status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN ); status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN );
if (!status) if (!status)
{ {
@ -358,10 +358,10 @@ static NTSTATUS query_shell_folder( void *buff, SIZE_T insize, SIZE_T outsize, I
break; break;
} }
if (status != STATUS_BUFFER_TOO_SMALL) break; if (status != STATUS_BUFFER_TOO_SMALL) break;
HeapFree( GetProcessHeap(), 0, buffer ); free( buffer );
} }
HeapFree( GetProcessHeap(), 0, buffer ); free( buffer );
return status; return status;
} }