From 161e8f4d5dbaa568975d61d770144484e14a62e0 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Fri, 8 Jan 2021 16:17:44 +0200 Subject: [PATCH] QProcess/Win: clean up death notifier teardown To avoid the mostly hypothetical possibility of failure, delete the processFinishedNotifier before closing the handle on which it operates. Previously, because of this, we explicitly disabled the notifier in the processFinished() function, which made the code unclear. Now, we can remove that safely, because cleanup() works correctly, and doing it before calling findExitCode() was not necessary to start with. Change-Id: Ia7095ded2c7eba8f4d738c6b87c7be41aa3cbbc8 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 48db7cdd543..9170b72e56b 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -849,12 +849,6 @@ void QProcessPrivate::cleanup() { q_func()->setProcessState(QProcess::NotRunning); #ifdef Q_OS_WIN - if (pid) { - CloseHandle(pid->hThread); - CloseHandle(pid->hProcess); - delete pid; - pid = 0; - } if (stdinWriteTrigger) { delete stdinWriteTrigger; stdinWriteTrigger = 0; @@ -863,9 +857,15 @@ void QProcessPrivate::cleanup() delete processFinishedNotifier; processFinishedNotifier = 0; } - -#endif + if (pid) { + CloseHandle(pid->hThread); + CloseHandle(pid->hProcess); + delete pid; + pid = nullptr; + } +#else pid = 0; +#endif if (stdoutChannel.notifier) { delete stdoutChannel.notifier; @@ -1165,10 +1165,6 @@ void QProcessPrivate::processFinished() #ifdef Q_OS_UNIX waitForDeadChild(); -#endif -#ifdef Q_OS_WIN - if (processFinishedNotifier) - processFinishedNotifier->setEnabled(false); #endif findExitCode();