summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorJosé Fonseca <jose.r.fonseca@gmail.com>2011-11-24 16:30:49 +0000
committerJosé Fonseca <jose.r.fonseca@gmail.com>2011-11-24 16:30:49 +0000
commit56cd8ac47208f0b649dcf4f24387e193861b6ed0 (patch)
treed0c59377804f823749eb0acb55776a2743fb2002 /gui
parentb50e9a86a69c715503c40bcc5069aae8e524261e (diff)
Prevent segfault on glretrace crash (fixes issue #52).
On glretrace crash, both error and finished QProcess events are emitted, by this order. Members were reset on error, causing null pointer dereference on replayFinished. Fix this by handling abnormal termination on replayFinished too. replayError should probably removed/merged into replayFinished.
Diffstat (limited to 'gui')
-rw-r--r--gui/retracer.cpp32
-rw-r--r--gui/retracer.h2
2 files changed, 24 insertions, 10 deletions
diff --git a/gui/retracer.cpp b/gui/retracer.cpp
index eaa86e3..0733617 100644
--- a/gui/retracer.cpp
+++ b/gui/retracer.cpp
@@ -141,7 +141,7 @@ void RetraceProcess::start()
}
-void RetraceProcess::replayFinished()
+void RetraceProcess::replayFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
QByteArray output = m_process->readAllStandardOutput();
QString msg;
@@ -152,14 +152,21 @@ void RetraceProcess::replayFinished()
qDebug()<<"\terr = "<<errStr;
qDebug()<<"\tout = "<<output;
#endif
- if (m_captureState) {
- bool ok = false;
- QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
- ApiTraceState *state = new ApiTraceState(parsedJson);
- emit foundState(state);
- msg = tr("State fetched.");
+
+ if (exitStatus != QProcess::NormalExit) {
+ msg = QLatin1String("Process crashed");
+ } else if (exitCode != 0) {
+ msg = QLatin1String("Process exited with non zero exit code");
} else {
- msg = QString::fromUtf8(output);
+ if (m_captureState) {
+ bool ok = false;
+ QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
+ ApiTraceState *state = new ApiTraceState(parsedJson);
+ emit foundState(state);
+ msg = tr("State fetched.");
+ } else {
+ msg = QString::fromUtf8(output);
+ }
}
QStringList errorLines = errStr.split('\n');
@@ -182,9 +189,16 @@ void RetraceProcess::replayFinished()
void RetraceProcess::replayError(QProcess::ProcessError err)
{
+ /*
+ * XXX: this function is likely unnecessary and should be eliminated given
+ * that replayFinished is always called, even on errors.
+ */
+
+#if 0
qDebug()<<"Process error = "<<err;
qDebug()<<"\terr = "<<m_process->readAllStandardError();
qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
+#endif
emit error(
tr("Couldn't execute the replay file '%1'").arg(m_fileName));
@@ -200,7 +214,7 @@ RetraceProcess::RetraceProcess(QObject *parent)
qRegisterMetaType<QList<ApiTraceError> >();
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(replayFinished()));
+ this, SLOT(replayFinished(int, QProcess::ExitStatus)));
connect(m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(replayError(QProcess::ProcessError)));
}
diff --git a/gui/retracer.h b/gui/retracer.h
index 4a43c26..127c9ab 100644
--- a/gui/retracer.h
+++ b/gui/retracer.h
@@ -48,7 +48,7 @@ signals:
void retraceErrors(const QList<ApiTraceError> &errors);
private slots:
- void replayFinished();
+ void replayFinished(int exitCode, QProcess::ExitStatus exitStatus);
void replayError(QProcess::ProcessError err);
private: