From 0a32845f820747fc32bbcc76214f129c8d5efe10 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Mon, 24 May 2021 22:14:24 +0300 Subject: [PATCH] Memory leak has been fixed --- common.pri | 2 +- limereport/lrscriptenginemanager.cpp | 12 ++++++------ limereport/lrscriptenginemanager.h | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/common.pri b/common.pri index 05621cc..829478f 100644 --- a/common.pri +++ b/common.pri @@ -126,7 +126,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 5 -LIMEREPORT_VERSION_RELEASE = 85 +LIMEREPORT_VERSION_RELEASE = 86 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index dcbec19..2cb9713 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -488,9 +488,9 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue, return context; } -QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue, QObject *reportItem, ScriptEngineType* se, ScriptNode *scriptTree) +QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue, QObject *reportItem, ScriptEngineType* se, ScriptNode::Ptr scriptTree) { - foreach(ScriptNode* item, scriptTree->children()){ + foreach(ScriptNode::Ptr item, scriptTree->children()){ QString scriptBody = expandDataFields(item->body(), EscapeSymbols, varValue, reportItem); if (item->children().size() > 0) scriptBody = replaceScripts(scriptBody, varValue, reportItem, se, item); @@ -529,7 +529,7 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){ ScriptExtractor scriptExtractor(script); if (scriptExtractor.parse()){ - QString scriptBody = expandDataFields(scriptExtractor.scriptTree()[0].body(), EscapeSymbols, varValue, 0); + QString scriptBody = expandDataFields(scriptExtractor.scriptTree()->body(), EscapeSymbols, varValue, 0); scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue); ScriptValueType value = se->evaluate(scriptBody); #ifdef USE_QJSENGINE @@ -987,7 +987,7 @@ bool ScriptExtractor::parse() return m_scriptTree->children().count() > 0; } -bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode* scriptNode) +bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode::Ptr scriptNode) { while (curPos Ptr; QString body(){return m_body;} void setBody(const QString& body){ m_body = body;} void setStartLex(const QString startLex){ m_startLex = startLex;} QString script(){return m_startLex + m_body + '}';} - ScriptNode* createChildNode(){ - ScriptNode* result = new ScriptNode(); + Ptr createChildNode(){ + Ptr result = Ptr(new ScriptNode()); m_children.append(result); return result; } - QVector children() const {return m_children;} + QVector children() const {return m_children;} private: - QVector m_children; + QVector m_children; QString m_body; QString m_startLex; }; @@ -421,22 +422,22 @@ class ScriptExtractor public: enum State{None,BuksFound,SFound,StartScriptFound,OpenBracketFound,CloseBracketFound,DFound,VFound, SignFound}; explicit ScriptExtractor(const QString& value): - m_context(value), m_scriptTree(new ScriptNode()){} + m_context(value), m_scriptTree(ScriptNode::Ptr(new ScriptNode())){} bool parse(); - ScriptNode* scriptTree(){return m_scriptTree;} + ScriptNode::Ptr scriptTree(){return m_scriptTree;} private: bool isStartLexem(int &curPos, QChar value); - bool parse(int& curPos, const State &state, ScriptNode *scriptNode); + bool parse(int& curPos, const State &state, ScriptNode::Ptr scriptNode); void skipField(int &curPos); - void extractScript(int& curPos, const QString &startStr, ScriptNode *scriptNode); - bool extractBracket(int& curPos, ScriptNode *scriptNode); + void extractScript(int& curPos, const QString &startStr, ScriptNode::Ptr scriptNode); + bool extractBracket(int& curPos, ScriptNode::Ptr scriptNode); bool isStartScriptLexem(int &curPos); bool isStartFieldLexem(int &curPos); bool isStartVariableLexem(int &curPos); QString substring(const QString& value, int start, int end); private: QString m_context; - ScriptNode* m_scriptTree; + ScriptNode::Ptr m_scriptTree; }; class ScriptEngineManager : public QObject, public Singleton, public IScriptEngineManager @@ -467,7 +468,7 @@ public: QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem); QString expandScripts(QString context, QVariant &varValue, QObject* reportItem); - QString replaceScripts(QString context, QVariant& varValue, QObject *reportItem, ScriptEngineType *se, ScriptNode* scriptTree); + QString replaceScripts(QString context, QVariant& varValue, QObject *reportItem, ScriptEngineType *se, ScriptNode::Ptr scriptTree); QVariant evaluateScript(const QString &script); void addBookMark(const QString &uniqKey, const QString &content);