summaryrefslogtreecommitdiff
path: root/ui/updateinfo.h
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-07-11 10:01:52 -0700
committerMark Rowe <mark@vector35.com>2025-07-11 11:00:26 -0700
commit41507e5f49989fbf60f303270e0a051b546469f4 (patch)
tree35d7d3b6a4b98f0151297b4bb69fc5adf021b14d /ui/updateinfo.h
parentc7e81986909d61ff5c7e817680dcfb78809449b5 (diff)
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`.
Diffstat (limited to 'ui/updateinfo.h')
-rw-r--r--ui/updateinfo.h14
1 files changed, 12 insertions, 2 deletions
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 <QObject>
#include <QVersionNumber>
#include <QDateTime>
+#include <memory>
#include "binaryninjaapi.h"
-class BINARYNINJAUIAPI UpdateInfoFetcher : public QObject
+class BINARYNINJAUIAPI UpdateInfoFetcher : public QObject, public std::enable_shared_from_this<UpdateInfoFetcher>
{
Q_OBJECT
@@ -60,8 +61,17 @@ private:
std::mutex m_infoMutex;
std::atomic<bool> m_done = false;
+ struct UseCreate {};
+
public:
- UpdateInfoFetcher() {};
+ // Instances must be created via `create()`.
+ UpdateInfoFetcher(UseCreate) {}
+
+ static std::shared_ptr<UpdateInfoFetcher> create();
+
+ UpdateInfoFetcher(const UpdateInfoFetcher&) = delete;
+ UpdateInfoFetcher& operator=(const UpdateInfoFetcher&) = delete;
+
bool done() { return m_done; }
void startFetch();
const std::vector<Channel>& getChannels();