diff --git a/input/connect/connect_ps3.c b/input/connect/connect_ps3.c index 7315339f0d..f4bc3da15d 100644 --- a/input/connect/connect_ps3.c +++ b/input/connect/connect_ps3.c @@ -60,9 +60,15 @@ static void* hidpad_ps3_connect(void *connect_data, uint32_t slot, send_control_ struct hidpad_ps3_data* device = (struct hidpad_ps3_data*) calloc(1, sizeof(struct hidpad_ps3_data)); - if (!device || !connection) + if (!device) return NULL; + if (!connection) + { + free(device); + return NULL; + } + device->connection = connection; device->slot = slot; device->send_control = ptr; diff --git a/input/connect/connect_ps4.c b/input/connect/connect_ps4.c index 2ab3dedf2d..1c3ff2b382 100644 --- a/input/connect/connect_ps4.c +++ b/input/connect/connect_ps4.c @@ -54,9 +54,15 @@ static void* hidpad_ps4_connect(void *connect_data, uint32_t slot, send_control_ struct hidpad_ps4_data* device = (struct hidpad_ps4_data*) calloc(1, sizeof(struct hidpad_ps4_data)); - if (!device || !connection) + if (!device) return NULL; + if (!connection) + { + free(device); + return NULL; + } + device->connection = connection; device->slot = slot; device->send_control = ptr; diff --git a/input/connect/connect_wii.c b/input/connect/connect_wii.c index 6d9f108ca2..2aea8d2445 100644 --- a/input/connect/connect_wii.c +++ b/input/connect/connect_wii.c @@ -463,9 +463,15 @@ static void* hidpad_wii_connect(void *data, uint32_t slot, struct wiimote_t *device = (struct wiimote_t*) calloc(1, sizeof(struct wiimote_t)); - if (!device || !connection) + if (!device) return NULL; + if (!connection) + { + free(device); + return NULL; + } + device->connection = connection; device->unid = slot; device->state = WIIMOTE_STATE_CONNECTED;