summaryrefslogtreecommitdiff
path: root/function.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2023-11-14 18:35:38 -0500
committerGlenn Smith <glenn@vector35.com>2023-11-14 18:35:38 -0500
commit4025361513068463390900635313910200542556 (patch)
tree2dbfc8ef20c3eae8d849a02d833917dc24b28d28 /function.cpp
parent814d840c8d12dfcfb60a5bf172ea494825fd30c1 (diff)
Fix a number of leaks and bad uses of free in the api
See https://github.com/Vector35/binaryninja-api/issues/4751
Diffstat (limited to 'function.cpp')
-rw-r--r--function.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/function.cpp b/function.cpp
index 4ef91860..b95ed211 100644
--- a/function.cpp
+++ b/function.cpp
@@ -538,6 +538,31 @@ BNPossibleValueSet PossibleValueSet::ToAPIObject()
}
+void PossibleValueSet::FreeAPIObject(BNPossibleValueSet* value)
+{
+ switch (value->state)
+ {
+ case SignedRangeValue:
+ case UnsignedRangeValue:
+ delete[] value->ranges;
+ break;
+ case LookupTableValue:
+ for (size_t i = 0; i < value->count; i ++)
+ {
+ delete[] value->table[i].fromValues;
+ }
+ delete[] value->table;
+ break;
+ case InSetOfValues:
+ case NotInSetOfValues:
+ delete[] value->valueSet;
+ break;
+ default:
+ break;
+ }
+}
+
+
DataBuffer Function::GetConstantData(BNRegisterValueType state, uint64_t value, size_t size)
{
return DataBuffer(BNGetConstantData(m_object, state, value, size));
@@ -2533,6 +2558,8 @@ void Function::SetUserVariableValue(const Variable& var, uint64_t defAddr, Possi
auto valueObj = value.ToAPIObject();
BNSetUserVariableValue(m_object, &var_data, &defSite, &valueObj);
+
+ PossibleValueSet::FreeAPIObject(&valueObj);
}