summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2019-05-10 16:15:48 -0400
committerRusty Wagner <rusty@vector35.com>2019-05-10 16:15:48 -0400
commitf6659517c08799cf52fddd09424eaea867ff3ed7 (patch)
treeab06cf065b7c152dff91658c7247946cb7ffaec8 /binaryninjaapi.h
parent63a4020845a81cf8793ddb02c7d5c95e3317d2a1 (diff)
Fix memory leak and use after free bugs in BinaryView and FlowGraph objects
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 2df09818..daf3db4f 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -95,15 +95,22 @@ namespace BinaryNinja
{
#ifdef WIN32
if (InterlockedDecrement((LONG*)&m_refs) == 0)
- delete this;
+ {
+ if (!m_registeredRef)
+ delete this;
+ }
#else
if (__sync_fetch_and_add(&m_refs, -1) == 1)
- delete this;
+ {
+ if (!m_registeredRef)
+ delete this;
+ }
#endif
}
public:
int m_refs;
+ bool m_registeredRef = false;
T* m_object;
CoreRefCountObject(): m_refs(0), m_object(nullptr) {}
virtual ~CoreRefCountObject() {}
@@ -133,13 +140,15 @@ namespace BinaryNinja
void AddRefForRegistration()
{
- AddRefInternal();
+ m_registeredRef = true;
}
void ReleaseForRegistration()
{
m_object = nullptr;
- ReleaseInternal();
+ m_registeredRef = false;
+ if (m_refs == 0)
+ delete this;
}
};
@@ -2806,6 +2815,7 @@ namespace BinaryNinja
static void PopulateNodesCallback(void* ctxt);
static void CompleteLayoutCallback(void* ctxt);
static BNFlowGraph* UpdateCallback(void* ctxt);
+ static void FreeObjectCallback(void* ctxt);
protected:
FlowGraph(BNFlowGraph* graph);