From e71d12a6147d0a2dfe6ead94d31db30d36792087 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 9 Feb 2023 16:52:36 -0500 Subject: Fix crash caused by race condition on freeing plugin BinaryViews `FreeObjectReference` on `BinaryView` can be deferred to not block the UI on teardown of large binary views. This causes `ReleaseForRegistration` to be called at a later time, which could cause a race that permitted two threads to delete the object at the same time. Moving the `FreeObjectReference` to be after the API reference release causes `ReleaseForRegistration` to be always called after all API references have been completed, so it will no longer free twice. --- binaryninjaapi.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a5ad242d..c5724621 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -165,9 +165,10 @@ namespace BinaryNinja { void Release() { - if (m_object) - FreeObjectReference(m_object); + T* obj = m_object; ReleaseInternal(); + if (obj) + FreeObjectReference(obj); } void AddRefForRegistration() { m_registeredRef = true; } -- cgit v1.3.1