From c76ad34dc7c27ac61f88bcbc0ac11ebd17e1028f Mon Sep 17 00:00:00 2001 From: Anthony Platanios Date: Sat, 13 Apr 2019 11:34:52 -0400 Subject: [PATCH 1/2] Initial attempt to fix a bug. --- src/emulator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index b16b2f7f0..5cd2b27b4 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -360,7 +360,7 @@ bool Emulator::cbEnvironment(unsigned cmd, void* data) { return false; } case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY: - *reinterpret_cast(data) = corePath().c_str(); + *reinterpret_cast(data) = strdup(corePath().c_str()); return true; case RETRO_ENVIRONMENT_GET_CAN_DUPE: *reinterpret_cast(data) = true; From f0c96beb7396e2e17bcb840ca66d586e4c6af39a Mon Sep 17 00:00:00 2001 From: Anthony Platanios Date: Fri, 19 Jul 2019 14:43:23 -0400 Subject: [PATCH 2/2] Made requested changes. --- src/emulator.cpp | 8 +++++++- src/emulator.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index 5cd2b27b4..a74c279ba 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -58,6 +58,9 @@ Emulator::Emulator() { } Emulator::~Emulator() { + if (m_corePath) { + free(m_corePath); + } if (m_romLoaded) { unloadRom(); } @@ -360,7 +363,10 @@ bool Emulator::cbEnvironment(unsigned cmd, void* data) { return false; } case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY: - *reinterpret_cast(data) = strdup(corePath().c_str()); + if (!s_loadedEmulator->m_corePath) { + s_loadedEmulator->m_corePath = strdup(corePath().c_str()); + } + *reinterpret_cast(data) = s_loadedEmulator->m_corePath; return true; case RETRO_ENVIRONMENT_GET_CAN_DUPE: *reinterpret_cast(data) = true; diff --git a/src/emulator.h b/src/emulator.h index ce5dc3259..971a32200 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -83,6 +83,8 @@ class Emulator { retro_system_av_info m_avInfo = {}; std::vector m_map; + char* m_corePath = nullptr; + #ifdef _WIN32 HMODULE m_coreHandle = nullptr; #else