diff --git a/CHANGELOG.md b/CHANGELOG.md index 3527e9c0..5602a660 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - fixed asynchroniusly assigned PCA job not being properly detected [#1919](https://github.com/sandboxie-plus/Sandboxie/issues/1919) - fixed incompatybility with first windows 10 release [#3117](https://github.com/sandboxie-plus/Sandboxie/issues/3117) - fixed Remove Sandbox only deletes the contents of the sandbox when an application is running in the sandbox [#3118](https://github.com/sandboxie-plus/Sandboxie/issues/3118) +- fixed crash issue with not peroeprly termianted script engine [#3120](https://github.com/sandboxie-plus/Sandboxie/issues/3120) diff --git a/SandboxiePlus/SandMan/Engine/BoxEngine.cpp b/SandboxiePlus/SandMan/Engine/BoxEngine.cpp index a886f17c..84d2004f 100644 --- a/SandboxiePlus/SandMan/Engine/BoxEngine.cpp +++ b/SandboxiePlus/SandMan/Engine/BoxEngine.cpp @@ -22,11 +22,11 @@ #include #include -int CBoxEngine::m_InstanceCount = 0; +QSet CBoxEngine::m_Instances; CBoxEngine::CBoxEngine(QObject* parent) : QThread(parent) { - m_InstanceCount++; + m_Instances.insert(this); m_State = eUnknown; m_pEngine = NULL; @@ -37,6 +37,13 @@ CBoxEngine::CBoxEngine(QObject* parent) : QThread(parent) } CBoxEngine::~CBoxEngine() +{ + m_Instances.remove(this); + + Stop(); +} + +void CBoxEngine::Stop() { m_Mutex.lock(); if (m_State == eQuery || m_State == eReady) @@ -48,11 +55,16 @@ CBoxEngine::~CBoxEngine() } if (!wait(30 * 1000)) { - qDebug() << "Failed to terminate Box Engine"; - return; + qDebug() << "Failed to stop Box Engine"; + terminate(); + m_State = eCanceled; } +} - m_InstanceCount--; +void CBoxEngine::StopAll() +{ + foreach(CBoxEngine* pEngine, m_Instances) + pEngine->Stop(); } QV4::ReturnedValue method_translate(const QV4::FunctionObject *b, const QV4::Value *v, const QV4::Value *argv, int argc) @@ -288,9 +300,13 @@ QObject* CBoxEngine::GetDebuggerBackend() // CWizardEngine // +int CWizardEngine::m_InstanceCount = 0; + CWizardEngine::CWizardEngine(QObject* parent) : CBoxEngine(parent) { + + m_InstanceCount++; } CWizardEngine::~CWizardEngine() @@ -305,6 +321,8 @@ CWizardEngine::~CWizardEngine() } } theAPI->ReloadBoxes(true); + + m_InstanceCount--; } bool CWizardEngine::ApplyShadowChanges() @@ -376,7 +394,7 @@ QSharedPointer CWizardEngine::MakeShadow(const QSharedPointerGetName().toLower()]; if (!pShadow.pShadow) { QString ShadowName = pIni->GetName(); - QString Suffix = tr("_Shadow"); + QString Suffix = "_Shadow"; // do not translate must be a valid sandbox name suffix ShadowName.truncate(32 - (Suffix.length() + 3)); // BOXNAME_COUNT ShadowName = theAPI->MkNewName(ShadowName.append(Suffix)); @@ -455,4 +473,4 @@ void CWizardEngine::OpenOptions(const QString& box, const QString& page) }); //theGUI->SafeExec(pOptionsWnd); pOptionsWnd->showTab(page); -} +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Engine/BoxEngine.h b/SandboxiePlus/SandMan/Engine/BoxEngine.h index 9baa830e..a10f8871 100644 --- a/SandboxiePlus/SandMan/Engine/BoxEngine.h +++ b/SandboxiePlus/SandMan/Engine/BoxEngine.h @@ -14,6 +14,8 @@ public: bool RunScript(const QString& Script, const QString& Name, const QVariantMap& Params = QVariantMap()); + static void StopAll(); + enum EState { eUnknown, @@ -47,8 +49,6 @@ public: Q_INVOKABLE void AppendLog(const QString& Line); //QString GetLog() const { QMutexLocker Locker(&m_Mutex); return m_Log; } - static int GetInstanceCount() { return m_InstanceCount; } - CJSEngineExt* GetEngine() { return m_pEngine; } QObject* GetDebuggerBackend(); @@ -71,6 +71,7 @@ protected: virtual void init(); virtual void run(); + virtual void Stop(); //virtual bool Wait(); virtual bool Continue(bool bLocked, EState State = eRunning); @@ -92,7 +93,7 @@ protected: //QString m_Log; - static int m_InstanceCount; + static QSet m_Instances; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -115,6 +116,7 @@ public: void SetApplyShadow(const QString& OriginalName, bool bApply = true); bool IsNoAppliedShadow(const QString& OriginalName); + static int GetInstanceCount() { return m_InstanceCount; } Q_INVOKABLE void OpenSettings(const QString& page); Q_INVOKABLE void OpenOptions(const QString& box, const QString& page); @@ -136,5 +138,7 @@ protected: }; QMap m_Shadows; + + static int m_InstanceCount; }; diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index f558dcb3..29baee19 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -258,6 +258,7 @@ CSandMan::CSandMan(QWidget *parent) LoadState(); m_pProgressDialog = new CProgressDialog(""); + m_pProgressDialog->setWindowTitle("Sandboxie-Plus"); m_pProgressDialog->setWindowModality(Qt::ApplicationModal); connect(m_pProgressDialog, SIGNAL(Cancel()), this, SLOT(OnCancelAsync())); m_pProgressModal = false; @@ -313,6 +314,8 @@ CSandMan::~CSandMan() StoreState(); + CBoxEngine::StopAll(); + theAPI = NULL; theGUI = NULL; @@ -1501,7 +1504,7 @@ bool CSandMan::IsFullyPortable() bool CSandMan::KeepTerminated() { - if (CBoxEngine::GetInstanceCount() > 0) + if (CWizardEngine::GetInstanceCount() > 0) return true; return m_pKeepTerminated && m_pKeepTerminated->isChecked(); }