From c947b4c6a2dc40f89e67326606096cf94fbffc01 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 2 Apr 2015 09:16:21 -0400 Subject: [PATCH] hid: Fix return of potentially uninitialized pointers After a pointer is freed it's considered to be a dangling pointer. Returning a dangling pointer is undefined behavior. --- input/drivers_hid/apple_hid.c | 2 +- input/drivers_hid/null_hid.c | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/input/drivers_hid/apple_hid.c b/input/drivers_hid/apple_hid.c index 15bc04ee26..3e5f483b72 100644 --- a/input/drivers_hid/apple_hid.c +++ b/input/drivers_hid/apple_hid.c @@ -442,7 +442,7 @@ static void *apple_hid_init(void) error: if (hid_apple) free(hid_apple); - return hid_apple; + return NULL; } static void apple_hid_free(void *data) diff --git a/input/drivers_hid/null_hid.c b/input/drivers_hid/null_hid.c index 71849aa827..f9816dd6de 100644 --- a/input/drivers_hid/null_hid.c +++ b/input/drivers_hid/null_hid.c @@ -75,17 +75,7 @@ static int16_t null_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *null_hid_init(void) { - null_hid_t *hid_null = (null_hid_t*)calloc(1, sizeof(*hid_null)); - - if (!hid_null) - goto error; - - return hid_null; - -error: - if (hid_null) - free(hid_null); - return hid_null; + return (null_hid_t*)calloc(1, sizeof(null_hid_t)); } static void null_hid_free(void *data)