summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2019-02-13 10:09:54 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2019-02-21 14:33:29 +0000
commit46a20b90243149b0ecd1d44cab964e785648d214 (patch)
tree6beacad19da17cc82a410afc9704ddfa09558b28 /src
parent01f07fd2d1f4e9c6dfc755ffa1c30bb1281a0ff1 (diff)
QProcess: Fix crash when calling closeWriteChannel on Windows
We must deleteLater the pipe writer in closeChannel, because if you call closeWriteChannel() from a slot that is connected to a signal emitted from QWindowsPipeWriter, we'd operate on a deleted object. For consistency, we're calling QWindowsPipeWriter::stop before deleteLater and deduplicate the code. Fixes: QTBUG-73778 Change-Id: I61d3dedf57e9fd02517a108d13ffc85e006330f6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qprocess_win.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp
index cb4b2f9f91..3ba86063e3 100644
--- a/src/corelib/io/qprocess_win.cpp
+++ b/src/corelib/io/qprocess_win.cpp
@@ -362,16 +362,22 @@ 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) {
- delete stdinChannel.writer;
- stdinChannel.writer = 0;
- } else if (channel->reader) {
- channel->reader->stop();
- channel->reader->deleteLater();
- channel->reader = 0;
- }
+ if (channel == &stdinChannel)
+ deleteWorker(channel->writer);
+ else
+ deleteWorker(channel->reader);
destroyPipe(channel->pipe);
}