diff options
| author | Mark Rowe <mark@vector35.com> | 2025-07-11 10:01:52 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-07-11 11:00:26 -0700 |
| commit | 41507e5f49989fbf60f303270e0a051b546469f4 (patch) | |
| tree | 35d7d3b6a4b98f0151297b4bb69fc5adf021b14d /ui/updateinfo.h | |
| parent | c7e81986909d61ff5c7e817680dcfb78809449b5 (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.h | 14 |
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(); |
