Skip to content

Commit

Permalink
Allow destruction of QWindowsPipeReader in its signal
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Alex Trotsenko committed Jun 18, 2021
1 parent e6a9699 commit a73ec95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
21 changes: 7 additions & 14 deletions src/corelib/io/qprocess_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,15 @@ void QProcessPrivate::destroyPipe(Q_PIPE pipe[2])
}
}

template <class T>
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);
}

Expand Down
16 changes: 11 additions & 5 deletions src/corelib/io/qwindowspipereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "qwindowspipereader_p.h"
#include <qcoreapplication.h>
#include <QMutexLocker>
#include <QPointer>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -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<QWindowsPipeReader> 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;
Expand Down

0 comments on commit a73ec95

Please sign in to comment.