From 4b9a460fb62024bcb1ab915b2634b9ee4d620b22 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 18 Jan 2018 21:40:30 -0500 Subject: [PATCH] usb_comms: Correct scenarios when freeing the endpoint out buffer Previously g_usbComms_endpoint_out_buffer wouldnt be freed in usbCommsExit, as g_usbComms_endpoint_out would be set to NULL before the conditional check --- nx/source/runtime/devices/usb_comms.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/nx/source/runtime/devices/usb_comms.c b/nx/source/runtime/devices/usb_comms.c index 626ef687..51631f75 100644 --- a/nx/source/runtime/devices/usb_comms.c +++ b/nx/source/runtime/devices/usb_comms.c @@ -44,15 +44,11 @@ Result usbCommsInitialize(void) if (R_FAILED(ret)) { usbDsExit(); - if (g_usbComms_endpoint_in_buffer) { - free(g_usbComms_endpoint_in_buffer); - g_usbComms_endpoint_in_buffer = NULL; - } + free(g_usbComms_endpoint_in_buffer); + g_usbComms_endpoint_in_buffer = NULL; - if (g_usbComms_endpoint_out) { - free(g_usbComms_endpoint_out_buffer); - g_usbComms_endpoint_out_buffer = NULL; - } + free(g_usbComms_endpoint_out_buffer); + g_usbComms_endpoint_out_buffer = NULL; } } else { @@ -75,15 +71,11 @@ void usbCommsExit(void) g_usbComms_endpoint_in = NULL; g_usbComms_endpoint_out = NULL; - if (g_usbComms_endpoint_in_buffer) { - free(g_usbComms_endpoint_in_buffer); - g_usbComms_endpoint_in_buffer = NULL; - } + free(g_usbComms_endpoint_in_buffer); + g_usbComms_endpoint_in_buffer = NULL; - if (g_usbComms_endpoint_out) { - free(g_usbComms_endpoint_out_buffer); - g_usbComms_endpoint_out_buffer = NULL; - } + free(g_usbComms_endpoint_out_buffer); + g_usbComms_endpoint_out_buffer = NULL; } static Result _usbCommsInit(void)