diff options
author | Vikas Pachdha <[email protected]> | 2016-09-21 11:10:20 +0200 |
---|---|---|
committer | Vikas Pachdha <[email protected]> | 2016-09-21 10:38:15 +0000 |
commit | cf3afe885a1ea4a2e8f6d6d3b52282c6603156dd (patch) | |
tree | ee4519c0443316099b71c92621b9e3d8222ec47d /src/plugins/ios/iostoolhandler.cpp | |
parent | 1b7ea8437de754094274c13ab1b4dedfb5177c6d (diff) |
iOS: Fixes a random crash in Qt creator while closing
The Qt creator crashed randomly while closing. Fixed the iostool process
termination
Task-number: QTCREATORBUG-14862
Change-Id: Ib356020095fe23f277389ebe30d8dedf4380ec28
Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src/plugins/ios/iostoolhandler.cpp')
-rw-r--r-- | src/plugins/ios/iostoolhandler.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index 23481f74e83..35d3d3b2ed9 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -123,7 +123,7 @@ public: }; explicit IosToolHandlerPrivate(const IosDeviceType &devType, IosToolHandler *q); - virtual ~IosToolHandlerPrivate() {} + virtual ~IosToolHandlerPrivate(); virtual void requestTransferApp(const QString &bundlePath, const QString &deviceId, int timeout = 1000) = 0; virtual void requestRunApp(const QString &bundlePath, const QStringList &extraArgs, @@ -158,7 +158,7 @@ protected: void processXml(); IosToolHandler *q; - QProcess process; + QProcess *process; QTimer killTimer; QXmlStreamReader outputParser; QString deviceId; @@ -202,7 +202,12 @@ private: IosToolHandlerPrivate::IosToolHandlerPrivate(const IosDeviceType &devType, Ios::IosToolHandler *q) : - q(q), state(NonStarted), devType(devType), iBegin(0), iEnd(0), + q(q), + process(new QProcess), + state(NonStarted), + devType(devType), + iBegin(0), + iEnd(0), gdbSocket(-1) { killTimer.setSingleShot(true); @@ -225,22 +230,32 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(const IosDeviceType &devType, << QLatin1String("/System/Library/PrivateFrameworks"); env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), frameworkPaths.join(QLatin1Char(':'))); qCDebug(toolHandlerLog) << "IosToolHandler runEnv:" << env.toStringList(); - process.setProcessEnvironment(env); - QObject::connect(&process, &QProcess::readyReadStandardOutput, + process->setProcessEnvironment(env); + QObject::connect(process, &QProcess::readyReadStandardOutput, q, &IosToolHandler::subprocessHasData); - QObject::connect(&process, + QObject::connect(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), q, &IosToolHandler::subprocessFinished); - QObject::connect(&process, + QObject::connect(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), q, &IosToolHandler::subprocessError); QObject::connect(&killTimer, &QTimer::timeout, q, &IosToolHandler::killProcess); } +IosToolHandlerPrivate::~IosToolHandlerPrivate() +{ + if (isRunning()) { + process->terminate(); + if (!process->waitForFinished(1000)) + process->kill(); + } + delete process; +} + bool IosToolHandlerPrivate::isRunning() { - return process.state() != QProcess::NotRunning; + return process && (process->state() != QProcess::NotRunning); } void IosToolHandlerPrivate::start(const QString &exe, const QStringList &args) @@ -248,7 +263,7 @@ void IosToolHandlerPrivate::start(const QString &exe, const QStringList &args) QTC_CHECK(state == NonStarted); state = Starting; qCDebug(toolHandlerLog) << "running " << exe << args; - process.start(exe, args); + process->start(exe, args); state = StartedInferior; } @@ -283,9 +298,9 @@ void IosToolHandlerPrivate::stop(int errorCode) case Stopped: return; } - if (process.state() != QProcess::NotRunning) { - process.write("k\n\r"); - process.closeWriteChannel(); + if (isRunning()) { + process->write("k\n\r"); + process->closeWriteChannel(); killTimer.start(1500); } } @@ -556,8 +571,8 @@ void IosToolHandlerPrivate::subprocessHasData() // read some data { char buf[200]; - while (true) { - qint64 rRead = process.read(buf, sizeof(buf)); + while (isRunning()) { + qint64 rRead = process->read(buf, sizeof(buf)); if (rRead == -1) { stop(-1); return; @@ -706,8 +721,8 @@ void IosSimulatorToolHandlerPrivate::addDeviceArguments(QStringList &args) const void IosToolHandlerPrivate::killProcess() { - if (process.state() != QProcess::NotRunning) - process.kill(); + if (isRunning()) + process->kill(); } } // namespace Internal |