summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-10-19 00:00:00 -0400
committerPeter LaFosse <peter@vector35.com>2018-10-19 10:05:09 -0400
commitf0b34389d710dc2d7b7ca23cb0528e44ec0bb131 (patch)
tree954bbb990c5447cd3badd82adb781438081255b1
parent09b6de79ef14ee3eb5ee14d0bbb4cbebcddee2a1 (diff)
Fix memory leak in namespaces
-rw-r--r--binaryview.cpp6
-rw-r--r--metadata.cpp5
2 files changed, 10 insertions, 1 deletions
diff --git a/binaryview.cpp b/binaryview.cpp
index dfb79189..f0fdb70c 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1430,6 +1430,7 @@ Ref<Symbol> BinaryView::GetSymbolByRawName(const string& name, const NameSpace&
{
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol* sym = BNGetSymbolByRawName(m_object, name.c_str(), &ns);
+ NameSpace::FreeAPIObject(&ns);
if (!sym)
return nullptr;
return new Symbol(sym);
@@ -1441,6 +1442,7 @@ vector<Ref<Symbol>> BinaryView::GetSymbolsByName(const string& name, const NameS
size_t count;
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol** syms = BNGetSymbolsByName(m_object, name.c_str(), &count, &ns);
+ NameSpace::FreeAPIObject(&ns);
vector<Ref<Symbol>> result;
result.reserve(count);
@@ -1457,6 +1459,7 @@ vector<Ref<Symbol>> BinaryView::GetSymbols(const NameSpace& nameSpace)
size_t count;
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol** syms = BNGetSymbols(m_object, &count, &ns);
+ NameSpace::FreeAPIObject(&ns);
vector<Ref<Symbol>> result;
result.reserve(count);
@@ -1473,6 +1476,7 @@ vector<Ref<Symbol>> BinaryView::GetSymbols(uint64_t start, uint64_t len, const N
size_t count;
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol** syms = BNGetSymbolsInRange(m_object, start, len, &count, &ns);
+ NameSpace::FreeAPIObject(&ns);
vector<Ref<Symbol>> result;
result.reserve(count);
@@ -1489,6 +1493,7 @@ vector<Ref<Symbol>> BinaryView::GetSymbolsOfType(BNSymbolType type, const NameSp
size_t count;
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol** syms = BNGetSymbolsOfType(m_object, type, &count, &ns);
+ NameSpace::FreeAPIObject(&ns);
vector<Ref<Symbol>> result;
result.reserve(count);
@@ -1505,6 +1510,7 @@ vector<Ref<Symbol>> BinaryView::GetSymbolsOfType(BNSymbolType type, uint64_t sta
size_t count;
BNNameSpace ns = nameSpace.GetAPIObject();
BNSymbol** syms = BNGetSymbolsOfTypeInRange(m_object, type, start, len, &count, &ns);
+ NameSpace::FreeAPIObject(&ns);
vector<Ref<Symbol>> result;
result.reserve(count);
diff --git a/metadata.cpp b/metadata.cpp
index c111233f..08f9660c 100644
--- a/metadata.cpp
+++ b/metadata.cpp
@@ -112,7 +112,10 @@ bool Metadata::GetBoolean() const
string Metadata::GetString() const
{
- return BNMetadataGetString(m_object);
+ char* str = BNMetadataGetString(m_object);
+ string result = string(str);
+ BNFreeString(str);
+ return result;
}
uint64_t Metadata::GetUnsignedInteger() const