From 41507e5f49989fbf60f303270e0a051b546469f4 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 11 Jul 2025 10:01:52 -0700 Subject: Fix UpdateInfoFetcher lifetime issues `UpdateInfoFetcher` performs fetches asynchronously and needs to ensure it remains alive for the duration of the fetch. The fetch may not complete before its creator is destroyed, so `UpdateInfoFetcher` needs to control its own lifetime via `std::enable_shared_from_this`. --- ui/updateinfo.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/updateinfo.h b/ui/updateinfo.h index a3bf0d89..9e89b767 100644 --- a/ui/updateinfo.h +++ b/ui/updateinfo.h @@ -5,9 +5,10 @@ #include #include #include +#include #include "binaryninjaapi.h" -class BINARYNINJAUIAPI UpdateInfoFetcher : public QObject +class BINARYNINJAUIAPI UpdateInfoFetcher : public QObject, public std::enable_shared_from_this { Q_OBJECT @@ -60,8 +61,17 @@ private: std::mutex m_infoMutex; std::atomic m_done = false; + struct UseCreate {}; + public: - UpdateInfoFetcher() {}; + // Instances must be created via `create()`. + UpdateInfoFetcher(UseCreate) {} + + static std::shared_ptr create(); + + UpdateInfoFetcher(const UpdateInfoFetcher&) = delete; + UpdateInfoFetcher& operator=(const UpdateInfoFetcher&) = delete; + bool done() { return m_done; } void startFetch(); const std::vector& getChannels(); -- cgit v1.3.1