From 01ab13f62cabc9748c92e9ce7e337c1fc33eddd2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 30 Jun 2016 17:38:16 +0200 Subject: [PATCH] Prevent null pointer dereferences --- dynamic.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dynamic.c b/dynamic.c index 169484dd66..f94edf0592 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1352,15 +1352,18 @@ bool rarch_environment_cb(unsigned cmd, void *data) info[i].types[j].id); } - free(system->ports.data); - system->ports.data = (struct retro_controller_info*) - calloc(i, sizeof(*system->ports.data)); - if (!system->ports.data) - return false; + if (system) + { + free(system->ports.data); + system->ports.data = (struct retro_controller_info*) + calloc(i, sizeof(*system->ports.data)); + if (!system->ports.data) + return false; - memcpy(system->ports.data, info, - i * sizeof(*system->ports.data)); - system->ports.size = i; + memcpy(system->ports.data, info, + i * sizeof(*system->ports.data)); + system->ports.size = i; + } break; }