From cfa8da9ba0c429630b43a595e709057b8557dc55 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 2 Aug 2021 16:17:43 +0200 Subject: [PATCH] Base unique tokens on global atomic counter Don't base process token on instance pointer, as it may happen that the recreated instance may get the same token again (it happens often when invoking a function that recreates QtcProcess in sequence). The consequence may be that on the project launcher side we may reuse the old process (with possibly broken state) instead of creating a new one. Change-Id: I8274691f88ae0eefe008746d944a26f29979bf72 Reviewed-by: hjk --- src/libs/utils/qtcprocess.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index 46b4eb5f70d..36f0c6abe8e 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -275,11 +275,17 @@ private: ProcessHelper m_process; }; +static uint uniqueToken() +{ + static std::atomic_uint globalUniqueToken = 0; + return ++globalUniqueToken; +} + class ProcessLauncherImpl : public ProcessInterface { Q_OBJECT public: - ProcessLauncherImpl() : ProcessInterface() + ProcessLauncherImpl() : ProcessInterface(), m_token(uniqueToken()) { m_handle = LauncherInterface::socket()->registerHandle(token()); connect(m_handle, &LauncherHandle::errorOccurred, @@ -351,8 +357,9 @@ private: void handleSocketError(const QString &message); void handleSocketReady(); - quintptr token() const { return reinterpret_cast(this); } + quintptr token() const { return m_token; } + const uint m_token = 0; LauncherHandle *m_handle = nullptr; // This object lives in a different thread! };