From: Alex Henrie alexhenrie24@gmail.com
--- dlls/mountmgr.sys/device.c | 72 ++++++++++++++---------------------- dlls/mountmgr.sys/mountmgr.c | 30 +++++++-------- 2 files changed, 42 insertions(+), 60 deletions(-)
diff --git a/dlls/mountmgr.sys/device.c b/dlls/mountmgr.sys/device.c index bc934e2f494..c95faa172f7 100644 --- a/dlls/mountmgr.sys/device.c +++ b/dlls/mountmgr.sys/device.c @@ -113,24 +113,6 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; 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 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.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, name.MaximumLength ); + name.Buffer = malloc( name.MaximumLength ); for (i = first; i < 32; 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;
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 ); symlink.Length = lstrlenW(symlink.Buffer) * sizeof(WCHAR); @@ -732,9 +714,9 @@ static void delete_disk_device( struct disk_device *device ) IoDeleteSymbolicLink( &device->symlink ); RtlFreeUnicodeString( &device->symlink ); } - RtlFreeHeap( GetProcessHeap(), 0, device->unix_device ); - RtlFreeHeap( GetProcessHeap(), 0, device->unix_mount ); - RtlFreeHeap( GetProcessHeap(), 0, device->serial ); + free( device->unix_device ); + free( device->unix_mount ); + free( device->serial ); RtlFreeUnicodeString( &device->name ); IoDeleteDevice( device->dev_obj ); } @@ -758,7 +740,7 @@ static unsigned int release_volume( struct volume *volume ) list_remove( &volume->entry ); if (volume->mount) delete_mount_point( volume->mount ); delete_disk_device( volume->device ); - RtlFreeHeap( GetProcessHeap(), 0, volume ); + free( volume ); } return ret; } @@ -770,11 +752,11 @@ static void set_volume_udi( struct volume *volume, const char *udi ) { assert( !volume->udi ); /* 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) { - RtlFreeHeap( GetProcessHeap(), 0, volume->udi ); + free( volume->udi ); volume->udi = NULL; release_volume( volume ); } @@ -786,7 +768,7 @@ static NTSTATUS create_volume( const char *udi, enum device_type type, struct vo struct volume *volume; NTSTATUS status;
- if (!(volume = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*volume) ))) + if (!(volume = calloc( 1, sizeof(*volume) ))) return STATUS_NO_MEMORY;
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 ); *volume_ret = grab_volume( volume ); } - else RtlFreeHeap( GetProcessHeap(), 0, volume ); + else free( volume );
return status; } @@ -807,7 +789,7 @@ static NTSTATUS create_dos_device( struct volume *volume, const char *udi, int l struct dos_drive *drive; 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->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 ); *drive_ret = drive; } - else RtlFreeHeap( GetProcessHeap(), 0, drive ); + else free( drive );
return status; } @@ -835,7 +817,7 @@ static void delete_dos_device( struct dos_drive *drive ) list_remove( &drive->entry ); if (drive->mount) delete_mount_point( drive->mount ); release_volume( drive->volume ); - RtlFreeHeap( GetProcessHeap(), 0, drive ); + free( drive ); }
/* 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 */ if (devices & (1 << drive->drive)) { - HeapFree( GetProcessHeap(), 0, drive->volume->device->serial ); - drive->volume->device->serial = strdupA( device->serial ); + free( drive->volume->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 { - RtlFreeHeap( GetProcessHeap(), 0, disk_device->unix_device ); - RtlFreeHeap( GetProcessHeap(), 0, disk_device->unix_mount ); - RtlFreeHeap( GetProcessHeap(), 0, disk_device->serial ); + free( disk_device->unix_device ); + free( disk_device->unix_mount ); + free( disk_device->serial ); } - disk_device->unix_device = strdupA( device ); - disk_device->unix_mount = strdupA( mount_point ); - disk_device->serial = strdupA( disk_serial ); + disk_device->unix_device = strdup( device ); + disk_device->unix_mount = strdup( mount_point ); + disk_device->serial = strdup( disk_serial ); set_dos_devices_disk_serial( disk_device );
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; fs_type = get_mountmgr_fs_type( volume->fs_type ); serial = volume->serial; - device = strdupA( volume->device->unix_device ); - mount_point = strdupA( volume->device->unix_mount ); - label = strdupW( volume->label ); + device = strdup( volume->device->unix_device ); + mount_point = strdup( volume->device->unix_mount ); + label = wcsdup( volume->label ); release_volume( volume ); } 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; if (size > outsize) status = STATUS_BUFFER_OVERFLOW;
- RtlFreeHeap( GetProcessHeap(), 0, device ); - RtlFreeHeap( GetProcessHeap(), 0, mount_point ); - RtlFreeHeap( GetProcessHeap(), 0, label ); + free( device ); + free( mount_point ); + free( label ); return status; }
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c index b67082229f6..9f72eedb33b 100644 --- a/dlls/mountmgr.sys/mountmgr.c +++ b/dlls/mountmgr.sys/mountmgr.c @@ -48,9 +48,9 @@ static HKEY mount_key;
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 ); - 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 ); 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; 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); lstrcpyW( str, link ); @@ -116,8 +116,8 @@ void delete_mount_point( struct mount_point *mount ) list_remove( &mount->entry ); RegDeleteValueW( mount_key, mount->link.Buffer ); IoDeleteSymbolicLink( &mount->link ); - RtlFreeHeap( GetProcessHeap(), 0, mount->id ); - RtlFreeHeap( GetProcessHeap(), 0, mount ); + free( mount->id ); + free( mount ); }
/* 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; }
- input = HeapAlloc( GetProcessHeap(), 0, insize ); + input = malloc( insize ); if (!input) return STATUS_NO_MEMORY; memcpy( input, buff, insize ); @@ -217,7 +217,7 @@ static NTSTATUS query_mount_points( void *buff, SIZE_T insize, } info->Size = pos; iosb->Information = pos; - HeapFree( GetProcessHeap(), 0, input ); + free( input ); return STATUS_SUCCESS; }
@@ -298,7 +298,7 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize )
for (;;) { - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) + if (!(buffer = malloc( size ))) { status = STATUS_NO_MEMORY; 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_SUCCESS) break; if (status != STATUS_BUFFER_TOO_SMALL) goto done; - HeapFree( GetProcessHeap(), 0, buffer ); + free( buffer ); }
if (input->create_backup) { - if (!(backup = HeapAlloc( GetProcessHeap(), 0, strlen(buffer) + sizeof(".backup" ) ))) + if (!(backup = malloc( strlen(buffer) + sizeof(".backup" ) ))) { status = STATUS_NO_MEMORY; goto done; @@ -327,8 +327,8 @@ static NTSTATUS define_shell_folder( const void *in_buff, SIZE_T insize ) status = MOUNTMGR_CALL( set_shell_folder, ¶ms );
done: - HeapFree( GetProcessHeap(), 0, buffer ); - HeapFree( GetProcessHeap(), 0, backup ); + free( buffer ); + free( backup ); return status; }
@@ -348,7 +348,7 @@ static NTSTATUS query_shell_folder( void *buff, SIZE_T insize, SIZE_T outsize, I
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 ); if (!status) { @@ -358,10 +358,10 @@ static NTSTATUS query_shell_folder( void *buff, SIZE_T insize, SIZE_T outsize, I break; } if (status != STATUS_BUFFER_TOO_SMALL) break; - HeapFree( GetProcessHeap(), 0, buffer ); + free( buffer ); }
- HeapFree( GetProcessHeap(), 0, buffer ); + free( buffer ); return status; }