Skip to content

Commit

Permalink
Fix memory management bugs
Browse files Browse the repository at this point in the history
== DETAILS

 * Fix double-free in hidpad shutdown code
 * Fix possible double-free in hidpad error handling code
 * Fix memory leak in adapter delete method
  • Loading branch information
gblues committed Jan 28, 2018
1 parent 9e2d53d commit f2ea5dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions input/drivers_joypad/wiiu_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ static void build_pad_map(void)

static bool wiiu_joypad_init(void* data)
{
// the sub-drivers have to init first, otherwise
// build_pad_map will fail (because all lookups will return false).
/* the sub-drivers have to init first, otherwise
* build_pad_map will fail (because all lookups will return false). */
wpad_driver.init(data);
kpad_driver.init(data);
#ifdef WIIU_HID
Expand Down
15 changes: 9 additions & 6 deletions wiiu/input/hidpad_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static hid_driver_t *init_hid_driver(void)
if (hid_data)
{
wiiu_hid.free(hid_data);
free(hid_data);
hid_data = NULL;
}
return NULL;
Expand Down Expand Up @@ -93,12 +92,16 @@ static void hidpad_destroy(void)
{
ready = false;

if (!hid_driver)
return;
if(hid_driver) {
hid_driver->free(hid_data);
hid_data = NULL;
hid_driver = NULL;
}

hid_driver->free(get_hid_data());
free(hid_data);
hid_data = NULL;
if(hid_data) {
free(hid_data);
hid_data = NULL;
}
}

static bool hidpad_button(unsigned pad, uint16_t button)
Expand Down
11 changes: 7 additions & 4 deletions wiiu/input/wiiu_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ static void start_polling_thread(wiiu_hid_t *hid)
goto error;
}

RARCH_LOG("[hid]: thread: 0x%x; stack: 0x%x\n", thread, stack);

if (!OSCreateThread(thread,
wiiu_hid_polling_thread,
1, (char *)hid,
Expand Down Expand Up @@ -641,6 +639,11 @@ static void delete_adapter(wiiu_adapter_t *adapter)
free(adapter->rx_buffer);
adapter->rx_buffer = NULL;
}
if(adapter->tx_buffer)
{
free(adapter->tx_buffer);
adapter->tx_buffer = NULL;
}
free(adapter);
}

Expand All @@ -654,9 +657,9 @@ static wiiu_attach_event *new_attach_event(HIDDevice *device)
event->vendor_id = device->vid;
event->product_id = device->pid;
event->interface_index = device->interface_index;
event->is_keyboard = (device->sub_class == 1
event->is_keyboard = (device->sub_class == 1
&& device->protocol == 1);
event->is_mouse = (device->sub_class == 1
event->is_mouse = (device->sub_class == 1
&& device->protocol == 2);
event->max_packet_size_rx = device->max_packet_size_rx;
event->max_packet_size_tx = device->max_packet_size_tx;
Expand Down

0 comments on commit f2ea5dd

Please sign in to comment.