summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTuomas Tuononen <tuomas.tuononen@code-q.fi>2015-09-18 10:43:45 +0300
committerTuomas Tuononen <tuomas.tuononen@code-q.fi>2015-10-14 07:18:20 +0000
commit97bbd1f8b370584c0829ed4606e37e0de1bcb6db (patch)
treec494f5b36d007cf24f1b58f891d1e4bb0f6771c5
parentc780cd0a1d750b2f186acea99f254fcb2cc0e1b5 (diff)
SpeechRecognition: Fix a crash if destroyed while not idle
The crash could be easily reproduced by shutting down the application during engine initialization, while other initialization tasks were still in queue. Change-Id: Ieb688cd84397af10ac41ac37f88cf0a40c334dbe Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
-rwxr-xr-xsrc/asr/qspeechrecognitionmanager.cpp14
-rwxr-xr-xsrc/asr/qspeechrecognitionmanager_p.h2
2 files changed, 15 insertions, 1 deletions
diff --git a/src/asr/qspeechrecognitionmanager.cpp b/src/asr/qspeechrecognitionmanager.cpp
index ccc1309..923112c 100755
--- a/src/asr/qspeechrecognitionmanager.cpp
+++ b/src/asr/qspeechrecognitionmanager.cpp
@@ -50,6 +50,7 @@ QSpeechRecognitionManager::QSpeechRecognitionManager():
m_session(0),
m_listening(false),
m_muted(false),
+ m_exiting(false),
m_grammar()
{
}
@@ -58,6 +59,17 @@ QSpeechRecognitionManager::~QSpeechRecognitionManager()
{
foreach (QSpeechRecognitionPluginEngine* engine, m_engines)
engine->reset();
+ // Clear the containers and set the exiting flag to prevent access to the objects
+ // while they are being destroyed. This could happen if any of the children allow
+ // the events to be processed during destruction, which in turn may cause calls to
+ // QSpeechRecognitionManager API (e.g. createGrammar()).
+ m_engineLoaders.clear();
+ m_engines.clear();
+ m_grammars.clear();
+ m_grammar = GrammarInfo();
+ m_listening = false;
+ m_exiting = true;
+ qDeleteAll(findChildren<QSpeechRecognitionPluginLoader*>());
}
QSpeechRecognitionManager::AttributeData QSpeechRecognitionManager::getAttribute(const QString &key)
@@ -92,6 +104,8 @@ void QSpeechRecognitionManager::createEngine(const QString &engineName, const QS
{
QVariantMap errorParams;
errorParams.insert(QSpeechRecognition::Engine, engineName);
+ if (m_exiting)
+ return;
if (!m_engines.contains(engineName)) {
QSpeechRecognitionPluginEngine *engine = 0;
QSpeechRecognitionPluginLoader *engineLoader = m_engineLoaders.value(provider, 0);
diff --git a/src/asr/qspeechrecognitionmanager_p.h b/src/asr/qspeechrecognitionmanager_p.h
index e75e07b..79f561d 100755
--- a/src/asr/qspeechrecognitionmanager_p.h
+++ b/src/asr/qspeechrecognitionmanager_p.h
@@ -119,7 +119,7 @@ private:
int m_session;
bool m_listening;
bool m_muted;
- bool m_statChanged;
+ bool m_exiting;
GrammarInfo m_grammar;
QMap<QString, AttributeData> m_attributes;
QSet<QString> m_updatedAttributes;