summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptengine.cpp
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-01-28 10:10:31 +0100
committerKent Hansen <kent.hansen@nokia.com>2011-01-28 10:53:49 +0100
commitb127b1036ec75c625920a6c029b64a95e3702bf9 (patch)
tree6293c86030cdcd45e5cbb2a0ef5d9c3fab3b6f0b /src/script/api/qscriptengine.cpp
parentead20f4c1edc2e1c5c39f47bf7c9e56600d6362b (diff)
Invalidate QScriptPrograms when engine is destroyed
If the engine is destroyed before the program, the program must be invalidated; otherwise the program destructor will access a stale engine pointer, which can cause a crash (it crashes on Symbian, but "only" gives a Valgrind warning on Linux for our autotests). We need to keep track of all associated programs, just like we already do for values and strings. This fix follows the exact same pattern, but uses a QSet to keep the patch minimal. No new tests, but the evaluateProgram() test runs successfully on Symbian now, and there are no more Valgrind warnings. Task-number: QTBUG-16987 Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r--src/script/api/qscriptengine.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 9e338d4667..54039c0759 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -1022,6 +1022,7 @@ QScriptEnginePrivate::~QScriptEnginePrivate()
while (!ownedAgents.isEmpty())
delete ownedAgents.takeFirst();
+ detachAllRegisteredScriptPrograms();
detachAllRegisteredScriptValues();
detachAllRegisteredScriptStrings();
qDeleteAll(m_qobjectData);
@@ -1576,6 +1577,14 @@ bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue re
#endif
+void QScriptEnginePrivate::detachAllRegisteredScriptPrograms()
+{
+ QSet<QScriptProgramPrivate*>::const_iterator it;
+ for (it = registeredScriptPrograms.constBegin(); it != registeredScriptPrograms.constEnd(); ++it)
+ (*it)->detachFromEngine();
+ registeredScriptPrograms.clear();
+}
+
void QScriptEnginePrivate::detachAllRegisteredScriptValues()
{
QScriptValuePrivate *it;