@@ -69,6 +69,13 @@ public:
70 // Clear out any existing PAM interactions first
70 // Clear out any existing PAM interactions first
71 cancelPam();
71 cancelPam();
72+ if (pamHandle != nullptr) {
73+ // While we were cancelling pam above, we processed Qt events.
74+ // Which may have allowed someone to call start() on us again.
75+ // In which case, we'll bail on our current start() call.
76+ // This isn't racy because it's all in the same thread.
73 AppData *appData = new AppData();
80 AppData *appData = new AppData();
74 appData->impl = this;
81 appData->impl = this;
@@ -244,13 +251,21 @@ private:
244 void cancelPam()
251 void cancelPam()
246 if (pamHandle != nullptr) {
253 if (pamHandle != nullptr) {
254+ QFuture<int> pamFuture = futureWatcher.future();
247 pam_handle *handle = pamHandle;
255 pam_handle *handle = pamHandle;
248 pamHandle = nullptr; // to disable normal finishPam() handling
256 pamHandle = nullptr; // to disable normal finishPam() handling
249− futureWatcher.cancel();
257+ pamFuture.cancel();
259+ // Note the empty loop, we just want to clear the futures queue.
260+ // Any further prompts from the pam thread will be immediately
261+ // responded to/dismissed in handlePrompt().
262+ while (respond(QString()));
264+ // Now let signal/slot handling happen so the thread can finish
250− while (!futureWatcher.isFinished()) {
265+ while (!pamFuture.isFinished()) {
251− QCoreApplication::processEvents(); // let signal/slot handling happen
266+ QCoreApplication::processEvents();
254 pam_end(handle, PAM_CONV_ERR);
269 pam_end(handle, PAM_CONV_ERR);