Fix Stmt:Data object leak
authorLiang Jian <jianliang79@gmail.com>
Wed, 28 May 2014 07:46:51 +0000 (15:46 +0800)
committerjian liang <jianliang79@gmail.com>
Fri, 13 Jun 2014 13:50:06 +0000 (15:50 +0200)
call Stmt::destroyData() whenever a Stmt object is to be removed in
BasicBlock to delete the Stmt::Data object hold in the Stmt object.

Change-Id: I59c939d79b935153e6f8613e54f149120f5198f5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
src/qml/compiler/qv4jsir.cpp

index 5d30d6e3b9e08ce9cb639804b72fb88bbd7a2968..f81985c07dc6121ac35685fae1dbc8017b449785 100644 (file)
@@ -1049,6 +1049,11 @@ void BasicBlock::setStatements(const QVector<Stmt *> &newStatements)
 {
     Q_ASSERT(!isRemoved());
     Q_ASSERT(newStatements.size() >= _statements.size());
+    // FIXME: this gets quite inefficient for large basic-blocks, so this function/case should be re-worked.
+    foreach (Stmt *s, _statements) {
+        if (!newStatements.contains(s))
+            s->destroyData();
+    }
     _statements = newStatements;
 }
 
@@ -1088,18 +1093,21 @@ void BasicBlock::insertStatementBeforeTerminator(Stmt *stmt)
 void BasicBlock::replaceStatement(int index, Stmt *newStmt)
 {
     Q_ASSERT(!isRemoved());
+    _statements[index]->destroyData();
     _statements[index] = newStmt;
 }
 
 void BasicBlock::removeStatement(Stmt *stmt)
 {
     Q_ASSERT(!isRemoved());
+    stmt->destroyData();
     _statements.remove(_statements.indexOf(stmt));
 }
 
 void BasicBlock::removeStatement(int idx)
 {
     Q_ASSERT(!isRemoved());
+    _statements[idx]->destroyData();
     _statements.remove(idx);
 }