Skip to content

Commit 1f89af3

Browse files
ulfhermannqtQt Cherry-pick Bot
authored andcommitted
QtQml: Check for locals in metatypes stack frame before accessing them
ScopedStackFrame has no locals and we don't want to crash if we manage to run the GC while e.g. initializing a component. Amends commmit 2d016a2 Fixes: QTBUG-140057 Pick-to: 6.8 Change-Id: I7aeb39d6cb1f0ca0a661b8cfa2e7c159f968e224 Reviewed-by: Sami Shalayel <[email protected]> (cherry picked from commit 024e43c) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit c4bf8c9)
1 parent 407ee44 commit 1f89af3

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/qml/memory/qv4mm.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,13 @@ void MemoryManager::collectFromJSStack(MarkStack *markStack) const
14801480
if (!frame->isMetaTypesFrame())
14811481
continue;
14821482

1483-
const QQmlPrivate::AOTTrackedLocalsStorage *locals
1484-
= static_cast<const MetaTypesStackFrame *>(frame)->locals();
1485-
1486-
// locals have to be initialized first thing when calling the function
1487-
Q_ASSERT(locals);
1488-
1489-
locals->markObjects(markStack);
1483+
if (const QQmlPrivate::AOTTrackedLocalsStorage *locals
1484+
= static_cast<const MetaTypesStackFrame *>(frame)->locals()) {
1485+
// Actual AOT-compiled functions initialize the locals firsth thing when they
1486+
// are called. However, the ScopedStackFrame has no locals, but still uses a
1487+
// MetaTypesStackFrame.
1488+
locals->markObjects(markStack);
1489+
}
14901490
}
14911491
}
14921492

tests/auto/qml/qv4mm/tst_qv4mm.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ private slots:
5757
void scopedConvertToObjectFromReturnedValueDoesNotAccessGarbageOnTheStackOnAllocation();
5858
void scopedConvertToStringFromValueDoesNotAccessGarbageOnTheStackOnAllocation();
5959
void scopedConvertToObjectFromValueDoesNotAccessGarbageOnTheStackOnAllocation();
60+
61+
void dontCrashOnScopedStackFrame();
6062
};
6163

6264
tst_qv4mm::tst_qv4mm()
@@ -1019,6 +1021,17 @@ void tst_qv4mm::scopedConvertToObjectFromValueDoesNotAccessGarbageOnTheStackOnAl
10191021
QV4::ScopedObject object(scope, QV4::StaticValue::fromBoolean(true).asValue<QV4::Value>(), QV4::ScopedObject::Convert);
10201022
}
10211023

1024+
void tst_qv4mm::dontCrashOnScopedStackFrame()
1025+
{
1026+
QJSEngine jsengine;
1027+
QV4::ExecutionEngine *engine = jsengine.handle();
1028+
1029+
QV4::Scope scope(engine);
1030+
QV4::ScopedStackFrame frame(scope, engine->rootContext());
1031+
1032+
jsengine.collectGarbage();
1033+
}
1034+
10221035
QTEST_MAIN(tst_qv4mm)
10231036

10241037
#include "tst_qv4mm.moc"

0 commit comments

Comments
 (0)