Fix possible crashes
authorLars Knoll <lars.knoll@digia.com>
Fri, 11 Oct 2013 12:58:45 +0000 (14:58 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 11 Oct 2013 17:33:41 +0000 (19:33 +0200)
This can (and does crash) when a gc gets triggered during the
linking stage of a compilation unit.

Change-Id: I06f1299adab68ff8e0a4755d02e246870797e7f2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/compiler/qv4compileddata.cpp

index cd46730..887edc0 100644 (file)
@@ -98,6 +98,7 @@ QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
 
     if (data->lookupTableSize) {
         runtimeLookups = new QV4::Lookup[data->lookupTableSize];
+        memset(runtimeLookups, 0, data->lookupTableSize * sizeof(QV4::Lookup));
         const CompiledData::Lookup *compiledLookups = data->lookupTable();
         for (uint i = 0; i < data->lookupTableSize; ++i) {
             QV4::Lookup *l = runtimeLookups + i;
@@ -166,13 +167,17 @@ void CompilationUnit::markObjects()
 {
     for (int i = 0; i < data->stringTableSize; ++i)
         runtimeStrings[i].mark();
-    for (int i = 0; i < data->regexpTableSize; ++i)
-        runtimeRegularExpressions[i].mark();
+    if (runtimeRegularExpressions) {
+        for (int i = 0; i < data->regexpTableSize; ++i)
+            runtimeRegularExpressions[i].mark();
+    }
     for (int i = 0; i < runtimeFunctions.count(); ++i)
         if (runtimeFunctions[i])
             runtimeFunctions[i]->mark();
-    for (int i = 0; i < data->lookupTableSize; ++i)
-        runtimeLookups[i].name->mark();
+    if (runtimeLookups) {
+        for (int i = 0; i < data->lookupTableSize; ++i)
+            runtimeLookups[i].name->mark();
+    }
 }
 
 QString Binding::valueAsString(const Unit *unit) const