diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 16fb2be0aee..878f52fd004 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -834,9 +834,7 @@ void QProcessPrivate::cleanup() delete stateNotifier; stateNotifier = nullptr; } - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); - closeChannel(&stdinChannel); + closeChannels(); destroyPipe(childStartedPipe); #ifdef Q_OS_UNIX if (forkfd != -1) @@ -923,6 +921,16 @@ bool QProcessPrivate::openChannels() return true; } +/*! + \internal +*/ +void QProcessPrivate::closeChannels() +{ + closeChannel(&stdoutChannel); + closeChannel(&stderrChannel); + closeChannel(&stdinChannel); +} + /*! \internal */ diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index f1572055f40..6df359e4414 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -326,6 +326,7 @@ public: #endif void closeChannel(Channel *channel); void closeWriteChannel(); + void closeChannels(); bool tryReadFromChannel(Channel *channel); // obviously, only stdout and stderr QString program; diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 4fa36238a7b..d31691d9507 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -885,9 +885,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) if (!openChannelsForDetached()) { // openChannel sets the error string - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return false; } @@ -935,9 +933,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) } int savedErrno = errno; - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); if (childPid == -1) { setErrorAndEmit(QProcess::FailedToStart, QLatin1String("fork: ") + qt_error_string(savedErrno)); diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 388e163317f..24a6e2109c7 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -905,9 +905,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) if (!openChannelsForDetached()) { // openChannel sets the error string - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return false; } @@ -955,9 +953,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) setErrorAndEmit(QProcess::FailedToStart); } - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return success; }