summaryrefslogtreecommitdiff
path: root/debuginfo.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-02-02 19:34:27 -0500
committerMason Reed <mason@vector35.com>2025-02-13 13:00:05 -0500
commitee5063327e3ddefaa59ee2ff90e6e9f54eca2076 (patch)
tree15fd185a398de6a08832839cd78f1fbe5393b86a /debuginfo.cpp
parent1014cb1872c06b7dbfbee55d4a0b4e6a5743ec6b (diff)
Fix leaking BNDataVariableAndName when calling BNGetDebugDataVariableBy functions
Diffstat (limited to 'debuginfo.cpp')
-rw-r--r--debuginfo.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/debuginfo.cpp b/debuginfo.cpp
index 68eeba70..3e2b5ce9 100644
--- a/debuginfo.cpp
+++ b/debuginfo.cpp
@@ -158,27 +158,25 @@ Ref<Type> DebugInfo::GetTypeByName(const string& parserName, const string& name)
optional<tuple<uint64_t, Ref<Type>>> 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<Type>(new Type(result->type))}};
- }
- return {};
+ BNDataVariableAndName result;
+ if (!BNGetDebugDataVariableByName(m_object, parserName.c_str(), name.c_str(), &result))
+ return std::nullopt;
+ Ref<Type> type = new Type(BNNewTypeReference(result.type));
+ BNFreeDataVariableAndName(&result);
+ return {{result.address, type}};
}
optional<tuple<string, Ref<Type>>> DebugInfo::GetDataVariableByAddress(
const string& parserName, const uint64_t address) const
{
- BNDataVariableAndName* nameAndVar = BNGetDebugDataVariableByAddress(m_object, parserName.c_str(), address);
- if (nameAndVar)
- {
- const tuple<string, Ref<Type>> result = {nameAndVar->name, Ref<Type>(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> type = new Type(BNNewTypeReference(result.type));
+ BNFreeDataVariableAndName(&result);
+ return {{name, type}};
}