From 11d3ba7689adef3c255e29def25537db13c4246b Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 14 Jul 2024 20:14:32 +0200 Subject: [PATCH] Fix #141 - double free bug in SleighAsm, crashing only on Windows * std::string behaves different depending on char* char[] and const char* --- src/SleighAsm.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/SleighAsm.cpp b/src/SleighAsm.cpp index fb658958..395fa6da 100644 --- a/src/SleighAsm.cpp +++ b/src/SleighAsm.cpp @@ -400,7 +400,7 @@ RConfig *SleighAsm::getConfig(RAnal *a) { return core->config; } -std::string SleighAsm::getSleighHome(RConfig *cfg) { +std::string SleighAsm::getSleighHome(R_NULLABLE RConfig *cfg) { const char varname[] = "r2ghidra.sleighhome"; char *path = nullptr; @@ -419,7 +419,6 @@ std::string SleighAsm::getSleighHome(RConfig *cfg) { r_config_set (cfg, varname, ev); } std::string res (ev); - free (ev); return res; } @@ -435,7 +434,6 @@ std::string SleighAsm::getSleighHome(RConfig *cfg) { r_config_set (cfg, varname, path); } std::string res (path); - free ((void *)path); return res; } free ((void *)path); @@ -445,7 +443,6 @@ std::string SleighAsm::getSleighHome(RConfig *cfg) { r_config_set (cfg, varname, path); } std::string res (path); - free ((void *)path); return res; } else { #ifdef R2GHIDRA_SLEIGHHOME_DEFAULT @@ -453,7 +450,8 @@ std::string SleighAsm::getSleighHome(RConfig *cfg) { if (cfg) { r_config_set (cfg, varname, R2GHIDRA_SLEIGHHOME_DEFAULT); } - return R2GHIDRA_SLEIGHHOME_DEFAULT; + std::string res (R2GHIDRA_SLEIGHHOME_DEFAULT); + return res; } #endif R_LOG_ERROR ("Cannot find the sleigh home at '%s'. Fix it with `r2pm -ci r2ghidra-sleigh`", path);