From ee5063327e3ddefaa59ee2ff90e6e9f54eca2076 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 2 Feb 2025 19:34:27 -0500 Subject: Fix leaking BNDataVariableAndName when calling BNGetDebugDataVariableBy functions --- debuginfo.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'debuginfo.cpp') diff --git a/debuginfo.cpp b/debuginfo.cpp index 68eeba70..3e2b5ce9 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -158,27 +158,25 @@ Ref DebugInfo::GetTypeByName(const string& parserName, const string& name) optional>> DebugInfo::GetDataVariableByName( const string& parserName, const string& name) const { - BNDataVariableAndName* result = BNGetDebugDataVariableByName(m_object, parserName.c_str(), name.c_str()); - if (result) - { - BNFreeString(result->name); - return {{result->address, Ref(new Type(result->type))}}; - } - return {}; + BNDataVariableAndName result; + if (!BNGetDebugDataVariableByName(m_object, parserName.c_str(), name.c_str(), &result)) + return std::nullopt; + Ref type = new Type(BNNewTypeReference(result.type)); + BNFreeDataVariableAndName(&result); + return {{result.address, type}}; } optional>> DebugInfo::GetDataVariableByAddress( const string& parserName, const uint64_t address) const { - BNDataVariableAndName* nameAndVar = BNGetDebugDataVariableByAddress(m_object, parserName.c_str(), address); - if (nameAndVar) - { - const tuple> result = {nameAndVar->name, Ref(new Type(nameAndVar->type))}; - BNFreeString(nameAndVar->name); - return {result}; - } - return {}; + BNDataVariableAndName result; + if (!BNGetDebugDataVariableByAddress(m_object, parserName.c_str(), address, &result)) + return std::nullopt; + string name = result.name; + Ref type = new Type(BNNewTypeReference(result.type)); + BNFreeDataVariableAndName(&result); + return {{name, type}}; } -- cgit v1.3.1