diff --git a/dynamic.c b/dynamic.c index 022679388b..60c9febd2d 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1363,26 +1363,33 @@ bool rarch_environment_cb(unsigned cmd, void *data) case RETRO_ENVIRONMENT_SET_MEMORY_MAPS: { unsigned i; - struct retro_memory_descriptor *descriptors; - const struct retro_memory_map *mmaps = + struct retro_memory_descriptor *descriptors = NULL; + const struct retro_memory_map *mmaps = (const struct retro_memory_map*)data; - free((void*)system->mmaps.descriptors); - system->mmaps.num_descriptors = 0; + if (system) + { + RARCH_LOG("Environ SET_MEMORY_MAPS.\n"); + free((void*)system->mmaps.descriptors); + system->mmaps.num_descriptors = 0; + descriptors = (struct retro_memory_descriptor*) + calloc(mmaps->num_descriptors, + sizeof(*system->mmaps.descriptors)); + + if (!descriptors) + return false; + + system->mmaps.descriptors = descriptors; + memcpy((void*)system->mmaps.descriptors, mmaps->descriptors, + mmaps->num_descriptors * sizeof(*system->mmaps.descriptors)); + system->mmaps.num_descriptors = mmaps->num_descriptors; + mmap_preprocess_descriptors(descriptors, mmaps->num_descriptors); + } + else + { + RARCH_WARN("Environ SET_MEMORY_MAPS, but system pointer not initialized..\n"); + } - descriptors = (struct retro_memory_descriptor*) - calloc(mmaps->num_descriptors, sizeof(*system->mmaps.descriptors)); - - if (!descriptors) - return false; - - system->mmaps.descriptors = descriptors; - memcpy((void*)system->mmaps.descriptors, mmaps->descriptors, - mmaps->num_descriptors * sizeof(*system->mmaps.descriptors)); - system->mmaps.num_descriptors = mmaps->num_descriptors; - mmap_preprocess_descriptors(descriptors, mmaps->num_descriptors); - - RARCH_LOG("Environ SET_MEMORY_MAPS.\n"); if (sizeof(void *) == 8) RARCH_LOG(" ndx flags ptr offset start select disconn len addrspace\n"); diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index e396ff16a4..e95dd692df 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -133,7 +133,7 @@ static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x) x11_colormap_destroy(); - if (x->g_should_reset_mode) + if (x->g_should_reset_mode && g_x11_dpy) { x11_exit_fullscreen(g_x11_dpy, &x->g_desktop_mode); x->g_should_reset_mode = false; diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 936f4f374e..cbb9e45d4f 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -451,7 +451,7 @@ static int file_archive_decompress_data_to_file( } end: - if (handle->data) + if (handle && handle->data) free(handle->data); return ret; }