Fix leak of QString in V4 IR
authorSimon Hausmann <simon.hausmann@digia.com>
Mon, 12 Aug 2013 11:30:19 +0000 (13:30 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 12 Aug 2013 20:14:49 +0000 (22:14 +0200)
The destructors of the IR nodes won't be called because they come out of
a memory pool. Therefore we must store strings by pointer from the function's
string pool.

Change-Id: I841e801b81c871e8d08cf63ee1e053744c0bf4dc
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qv4codegen.cpp
src/qml/compiler/qv4isel_masm.cpp
src/qml/compiler/qv4isel_moth.cpp
src/qml/compiler/qv4jsir.cpp
src/qml/compiler/qv4jsir_p.h

index d0c43c8..969b358 100644 (file)
@@ -2389,7 +2389,7 @@ bool Codegen::visit(TryStatement *ast)
     int exception_to_rethrow  = _block->newTemp();
 
     _block->TRY(tryBody, catchBody,
-                ast->catchExpression ? ast->catchExpression->name.toString() : QString(),
+                _function->newString(ast->catchExpression ? ast->catchExpression->name.toString() : QString()),
                 _block->TEMP(exception_to_rethrow));
 
     _block = tryBody;
index 21c2c73..861ffbf 100644 (file)
@@ -888,7 +888,7 @@ void InstructionSelection::visitTry(V4IR::Try *t)
 
     generateFunctionCall(Assembler::ReturnValueRegister, tryWrapper, Assembler::ContextRegister, Assembler::LocalsRegister,
                          Assembler::ReentryBlock(t->tryBlock), Assembler::ReentryBlock(t->catchBlock),
-                         identifier(t->exceptionVarName), Assembler::PointerToValue(t->exceptionVar));
+                         identifier(*t->exceptionVarName), Assembler::PointerToValue(t->exceptionVar));
     _as->jump(Assembler::ReturnValueRegister);
 }
 
index 9313e24..8b86055 100644 (file)
@@ -728,7 +728,7 @@ void InstructionSelection::visitTry(V4IR::Try *t)
     Instruction::EnterTry enterTry;
     enterTry.tryOffset = 0;
     enterTry.catchOffset = 0;
-    enterTry.exceptionVarName = identifier(t->exceptionVarName);
+    enterTry.exceptionVarName = identifier(*t->exceptionVarName);
     enterTry.exceptionVar = getParam(t->exceptionVar);
     ptrdiff_t enterTryLoc = addInstruction(enterTry);
 
index 7f8d257..fcaf1a0 100644 (file)
@@ -881,7 +881,7 @@ Stmt *BasicBlock::RET(Temp *expr)
     return s;
 }
 
-Stmt *BasicBlock::TRY(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString &exceptionVarName, Temp *exceptionVar)
+Stmt *BasicBlock::TRY(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString *exceptionVarName, Temp *exceptionVar)
 {
     if (isTerminated())
         return 0;
index 364ff53..4b716fc 100644 (file)
@@ -640,10 +640,10 @@ struct Ret: Stmt {
 struct Try: Stmt {
     BasicBlock *tryBlock;
     BasicBlock *catchBlock;
-    QString exceptionVarName;
+    const QString *exceptionVarName;
     Temp *exceptionVar; // place to store the caught exception, for use when re-throwing
 
-    void init(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString &exceptionVarName, Temp *exceptionVar)
+    void init(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString *exceptionVarName, Temp *exceptionVar)
     {
         this->tryBlock = tryBlock;
         this->catchBlock = catchBlock;
@@ -816,7 +816,7 @@ struct BasicBlock {
     Stmt *JUMP(BasicBlock *target);
     Stmt *CJUMP(Expr *cond, BasicBlock *iftrue, BasicBlock *iffalse);
     Stmt *RET(Temp *expr);
-    Stmt *TRY(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString &exceptionVarName, Temp *exceptionVar);
+    Stmt *TRY(BasicBlock *tryBlock, BasicBlock *catchBlock, const QString *exceptionVarName, Temp *exceptionVar);
 
     void dump(QTextStream &out, Stmt::Mode mode = Stmt::HIR);