From 397c1d24a8f6da31a372e39ce2a0b5d98fb74d06 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 25 Dec 2016 02:05:34 +0100 Subject: [PATCH] Be more careful with allocations --- dynamic.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dynamic.c b/dynamic.c index fccd1fab31..4e232da3ae 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1452,13 +1452,18 @@ bool rarch_environment_cb(unsigned cmd, void *data) if (system) { + struct retro_subsystem_info *info_ptr = NULL; free(system->subsystem.data); - system->subsystem.data = (struct retro_subsystem_info*) - calloc(i, sizeof(*system->subsystem.data)); + system->subsystem.data = NULL; - if (!system->subsystem.data) + info_ptr = (struct retro_subsystem_info*) + calloc(i, sizeof(*info_ptr)); + + if (!info_ptr) return false; + system->subsystem.data = info_ptr; + memcpy(system->subsystem.data, info, i * sizeof(*system->subsystem.data)); system->subsystem.size = i; @@ -1484,12 +1489,16 @@ bool rarch_environment_cb(unsigned cmd, void *data) if (system) { + struct retro_controller_info *info_ptr = NULL; + free(system->ports.data); - system->ports.data = (struct retro_controller_info*) - calloc(i, sizeof(*system->ports.data)); - if (!system->ports.data) + system->ports.data = NULL; + + info_ptr = (struct retro_controller_info*)calloc(i, sizeof(*info_ptr)); + if (!info_ptr) return false; + system->ports.data = info_ptr; memcpy(system->ports.data, info, i * sizeof(*system->ports.data)); system->ports.size = i; @@ -1516,7 +1525,7 @@ bool rarch_environment_cb(unsigned cmd, void *data) if (!descriptors) return false; - system->mmaps.descriptors = descriptors; + system->mmaps.descriptors = descriptors; system->mmaps.num_descriptors = mmaps->num_descriptors; for (i = 0; i < mmaps->num_descriptors; i++)