From a73ec95c1e5aea907ac4618122f4715924c883e6 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 15 Jun 2021 19:51:36 +0300 Subject: [PATCH] Allow destruction of QWindowsPipeReader in its signal As a result, we can refrain from using the deleteLater() technique in QProcess and avoid long-lived soft leaks in blocking applications. Change-Id: I89e02b02551a668b995ad3d12d3ce9575b2dd9dd Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess_win.cpp | 21 +++++++-------------- src/corelib/io/qwindowspipereader.cpp | 16 +++++++++++----- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 65422659b0d..e557d104534 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -359,22 +359,15 @@ void QProcessPrivate::destroyPipe(Q_PIPE pipe[2]) } } -template -void deleteWorker(T *&worker) -{ - if (!worker) - return; - worker->stop(); - worker->deleteLater(); - worker = nullptr; -} - void QProcessPrivate::closeChannel(Channel *channel) { - if (channel == &stdinChannel) - deleteWorker(channel->writer); - else - deleteWorker(channel->reader); + if (channel == &stdinChannel) { + delete channel->writer; + channel->writer = nullptr; + } else { + delete channel->reader; + channel->reader = nullptr; + } destroyPipe(channel->pipe); } diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index d1a1782529b..4d2f008eebd 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -41,6 +41,7 @@ #include "qwindowspipereader_p.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -425,12 +426,17 @@ bool QWindowsPipeReader::consumePendingAndEmit(bool allowWinActPosting) if (state != Running) return false; - if (emitReadyRead) - emit readyRead(); - if (emitPipeClosed) { - if (dwError != ERROR_BROKEN_PIPE && dwError != ERROR_PIPE_NOT_CONNECTED) + if (!emitPipeClosed) { + if (emitReadyRead) + emit readyRead(); + } else { + QPointer alive(this); + if (emitReadyRead) + emit readyRead(); + if (alive && dwError != ERROR_BROKEN_PIPE && dwError != ERROR_PIPE_NOT_CONNECTED) emit winError(dwError, QLatin1String("QWindowsPipeReader::consumePendingAndEmit")); - emit pipeClosed(); + if (alive) + emit pipeClosed(); } return emitReadyRead;