comparison src/hgrunner.cpp @ 385:5cc0d897eb26

Avoid crash when one of the data output callbacks is called after m_proc has already been reset (fixing #132)
author Chris Cannam <chris.cannam@eecs.qmul.ac.uk>
date Tue, 24 May 2011 13:29:27 +0100
parents b9c153e00e84
children c567fed39559
comparison
equal deleted inserted replaced
384:2925975bdc9e 385:5cc0d897eb26
277 } 277 }
278 278
279 void HgRunner::dataReadyStdout() 279 void HgRunner::dataReadyStdout()
280 { 280 {
281 DEBUG << "dataReadyStdout" << endl; 281 DEBUG << "dataReadyStdout" << endl;
282 if (!m_proc) return;
282 QString chunk = QString::fromUtf8(m_proc->readAllStandardOutput()); 283 QString chunk = QString::fromUtf8(m_proc->readAllStandardOutput());
283 if (!checkPrompts(chunk)) { 284 if (!checkPrompts(chunk)) {
284 m_stdout += chunk; 285 m_stdout += chunk;
285 } 286 }
286 } 287 }
287 288
288 void HgRunner::dataReadyStderr() 289 void HgRunner::dataReadyStderr()
289 { 290 {
290 DEBUG << "dataReadyStderr" << endl; 291 DEBUG << "dataReadyStderr" << endl;
292 if (!m_proc) return;
291 QString chunk = QString::fromUtf8(m_proc->readAllStandardError()); 293 QString chunk = QString::fromUtf8(m_proc->readAllStandardError());
292 DEBUG << chunk; 294 DEBUG << chunk;
293 if (!checkPrompts(chunk)) { 295 if (!checkPrompts(chunk)) {
294 m_stderr += chunk; 296 m_stderr += chunk;
295 } 297 }
310 finished(-1, QProcess::CrashExit); 312 finished(-1, QProcess::CrashExit);
311 } 313 }
312 314
313 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus) 315 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
314 { 316 {
315 // Save the current action and reset m_currentAction before we 317 if (!m_proc) return;
318
319 // Save the current action and reset m_currentAction before we
316 // emit a signal to mark the completion; otherwise we may be 320 // emit a signal to mark the completion; otherwise we may be
317 // resetting the action after a slot has already tried to set it 321 // resetting the action after a slot has already tried to set it
318 // to something else to start a new action 322 // to something else to start a new action
319 323
320 HgAction completedAction = m_currentAction; 324 HgAction completedAction = m_currentAction;
354 358
355 void HgRunner::killCurrentCommand() 359 void HgRunner::killCurrentCommand()
356 { 360 {
357 if (m_isRunning) { 361 if (m_isRunning) {
358 m_currentAction.action = ACT_NONE; // so that we don't bother to notify 362 m_currentAction.action = ACT_NONE; // so that we don't bother to notify
359 m_proc->kill(); 363 if (m_proc) m_proc->kill();
360 } 364 }
361 } 365 }
362 366
363 void HgRunner::checkQueue() 367 void HgRunner::checkQueue()
364 { 368 {
481 485
482 void HgRunner::closeProcInput() 486 void HgRunner::closeProcInput()
483 { 487 {
484 DEBUG << "closeProcInput" << endl; 488 DEBUG << "closeProcInput" << endl;
485 489
486 m_proc->closeWriteChannel(); 490 if (m_proc) m_proc->closeWriteChannel();
487 } 491 }
488 492
489 void HgRunner::openTerminal() 493 void HgRunner::openTerminal()
490 { 494 {
491 #ifndef Q_OS_WIN32 495 #ifndef Q_OS_WIN32