Commit c6cc9237 authored by Victor Yacovlev's avatar Victor Yacovlev

Hard cleanups to avoid memory leaks

parent 51f48e97
......@@ -242,7 +242,7 @@ public:
}
else {
return ret;
}
}
}
private:
......@@ -327,6 +327,9 @@ int main(int argc, char **argv)
app->setSplashScreen(splashScreen);
}
#endif
return app->main();
int ret = app->main();
ExtensionSystem::PluginManager::destroy();
delete app;
return ret;
}
......@@ -645,10 +645,10 @@ void Editor::createConnections()
connect(cursor_, SIGNAL(updateRequest()), plane_, SLOT(updateCursor()));
connect(cursor_, SIGNAL(updateRequest(int,int)), plane_, SLOT(updateText(int,int)));
connect(autocompleteWidget_, SIGNAL(requestHelpForAlgorithm(QString)),
connect(autocompleteWidget_.data(), SIGNAL(requestHelpForAlgorithm(QString)),
this, SIGNAL(requestHelpForAlgorithm(QString)));
connect(autocompleteWidget_, SIGNAL(hidden()), plane_, SIGNAL(enableInsertActions()));
connect(autocompleteWidget_, SIGNAL(acceptedSuggestion(QString)),
connect(autocompleteWidget_.data(), SIGNAL(hidden()), plane_, SIGNAL(enableInsertActions()));
connect(autocompleteWidget_.data(), SIGNAL(acceptedSuggestion(QString)),
plane_, SLOT(finishAutoCompletion(QString)));
}
......
......@@ -148,7 +148,7 @@ private /* fields */:
QScrollBar * verticalScrollBar_;
class FindReplace * findReplace_;
class SuggestionsWindow * autocompleteWidget_;
QScopedPointer<class SuggestionsWindow> autocompleteWidget_;
QAction * copy_;
QAction * paste_;
......
......@@ -26,6 +26,9 @@ EditorPlugin::~EditorPlugin()
if (e.e)
delete e.e;
}
if (settingsPage_) {
delete settingsPage_;
}
}
......
......@@ -216,6 +216,9 @@ AnalizerPrivate::~AnalizerPrivate()
{
delete lexer;
delete pdAutomata;
delete builtinModules[0];
delete builtinModules[1];
delete builtinModules[2];
}
Analizer::~Analizer()
......
......@@ -9,8 +9,8 @@ namespace KumirCodeRun {
static const int MAXIMUM_SHOWN_TABLE_ITEMS_COUNT = 255;
KumVariablesModel::KumVariablesModel(
VM::KumirVM * vm,
VM::CriticalSectionLocker * mutex,
std::shared_ptr<VM::KumirVM> vm,
std::shared_ptr<VM::CriticalSectionLocker> mutex,
QObject *parent)
: QAbstractItemModel(parent)
......
......@@ -69,8 +69,8 @@ signals:
public slots:
protected:
explicit KumVariablesModel(VM::KumirVM * vm,
VM::CriticalSectionLocker * mutex,
explicit KumVariablesModel(std::shared_ptr<VM::KumirVM> vm,
std::shared_ptr<VM::CriticalSectionLocker> mutex,
QObject *parent = 0);
QModelIndex valueIndex(int row, int column, TableOfVariables * table) const;
......@@ -81,8 +81,8 @@ protected:
void emitValueChanged(const VM::Variable & variable, const QVector<int> & indeces);
private:
VM::KumirVM * vm_;
VM::CriticalSectionLocker * mutex_;
std::shared_ptr<VM::KumirVM> vm_;
std::shared_ptr<VM::CriticalSectionLocker> mutex_;
QHash<QModelIndex, QModelIndex> parents_;
mutable QList<KumVariableItem*> cache_;
mutable QHash<KumVariableItem*, QModelIndex> modelIndeces_;
......
......@@ -12,37 +12,21 @@ namespace KumirCodeRun {
using namespace VM;
using namespace Kumir;
class Mutex: public CriticalSectionLocker
{
public:
inline Mutex() { m = new QMutex; }
inline void lock() {
m->lock();
}
inline void unlock() {
m->unlock();
}
inline ~Mutex() { delete m; }
private:
QMutex * m;
};
Run::Run(QObject *parent) :
QThread(parent)
{
programLoaded = false;
vm = new KumirVM();
VMMutex_ = new Mutex;
vm.reset(new KumirVM);
VMMutex_.reset(new Mutex);
vm->setMutex(VMMutex_);
variablesModel_ = new KumVariablesModel(vm, VMMutex_, this);
originFunctionDeep_ = 0;
interactDoneFlag_ = stoppingFlag_ = stepDoneFlag_ = algDoneFlag_ = false;
stoppingMutex_ = new QMutex;
stepDoneMutex_ = new QMutex;
algDoneMutex_ = new QMutex;
interactDoneMutex_ = new QMutex;
stoppingMutex_.reset(new QMutex);
stepDoneMutex_.reset(new QMutex);
algDoneMutex_.reset(new QMutex);
interactDoneMutex_.reset(new QMutex);
runMode_ = RM_ToEnd;
vm->setDebuggingHandler(this);
......@@ -61,7 +45,7 @@ void Run::unlockVMMutex()
void Run::stop()
{
QMutexLocker l(stoppingMutex_);
QMutexLocker l(stoppingMutex_.data());
stoppingFlag_ = true;
if (!isRunning()) {
emit lineChanged(-1, 0u, 0u);
......
......@@ -6,6 +6,7 @@
#include "vm/vm.hpp"
#include "interfaces/actorinterface.h"
#include "kumvariablesmodel.h"
#include <memory>
namespace KumirCodeRun {
......@@ -14,6 +15,21 @@ using Kumir::real;
using VM::Variable;
using VM::AnyValue;
class Mutex: public VM::CriticalSectionLocker
{
public:
inline Mutex() { m = new QMutex; }
inline void lock() {
m->lock();
}
inline void unlock() {
m->unlock();
}
inline ~Mutex() { delete m; }
private:
QMutex * m;
};
class Run
: public QThread
, public VM::DebuggingInteractionHandler
......@@ -22,7 +38,7 @@ class Run
public:
enum RunMode { RM_StepOver, RM_ToEnd, RM_StepOut, RM_StepIn };
explicit Run(QObject *parent);
VM::KumirVM * vm;
std::shared_ptr<VM::KumirVM> vm;
bool programLoaded;
inline bool stopped() const { return stoppingFlag_; }
bool mustStop() const;
......@@ -103,24 +119,24 @@ protected :
RunMode runMode_;
bool stoppingFlag_;
QMutex * stoppingMutex_;
QScopedPointer<QMutex> stoppingMutex_;
bool stepDoneFlag_;
QMutex * stepDoneMutex_;
QScopedPointer<QMutex> stepDoneMutex_;
bool algDoneFlag_;
QMutex * algDoneMutex_;
QScopedPointer<QMutex> algDoneMutex_;
int originFunctionDeep_;
QMutex * interactDoneMutex_;
QScopedPointer<QMutex> interactDoneMutex_;
bool interactDoneFlag_;
QVariantList inputResult_;
QVariantList funcOptResults_;
QVariant funcResult_;
QString funcError_;
mutable class Mutex * VMMutex_;
mutable class std::shared_ptr<Mutex> VMMutex_;
KumVariablesModel * variablesModel_;
QString programLoadError_;
......
......@@ -8,6 +8,7 @@ const QString PluginManager::WorkspacesListKey = "WorkspacesList";
const QString PluginManager::CurrentWorkspaceKey = "CurrentWorkspace";
const QString PluginManager::SkipChooseWorkspaceKey = "SkipChooseWorkspace";
PluginManager::PluginManager()
: QObject()
, pImpl_(new PluginManagerImpl)
......@@ -50,6 +51,15 @@ PluginManager::~PluginManager()
}
void PluginManager::destroy()
{
PluginManager * pm = instance();
foreach (KPlugin * o, pm->pImpl_->objects) {
delete o;
}
pm->pImpl_->objects.clear();
}
SettingsPtr PluginManager::globalSettings() const
{
return pImpl_->mySettings;
......
......@@ -133,6 +133,8 @@ public:
/** Stops all plugins in reverse-order of creation */
void shutdown();
static void destroy();
public /*constants*/:
static const QString WorkspacesListKey;
......
......@@ -23,6 +23,8 @@
#define MAX_RECURSION_SIZE 4000
#endif
#define ShPtr std::shared_ptr
namespace VM {
......@@ -33,7 +35,7 @@ public /*typedefs*/:
public /*methods*/:
/** Set parsed Kumir bytecode */
inline void setProgram(const Bytecode::Data & data, bool isMain, const String & filename);
inline void setProgramDirectory(const Kumir::String & path) { programDirectory_ = path; }
inline void setProgramDirectory(const Kumir::String & path) { programDirectory_.clear(); programDirectory_ = path; }
inline bool loadProgramFromBinaryBuffer(std::list<char> & stream, bool isMain, const String & filename, String & error);
inline bool loadProgramFromTextBuffer(const std::string & stream, bool isMain, const String & filename, String & error);
......@@ -68,7 +70,7 @@ public /*methods*/:
* You must set actual Mutex implementation object
* (Qt or C++11) with methods: lock() and unlock()
*/
inline void setMutex(CriticalSectionLocker * m)
inline void setMutex(ShPtr<CriticalSectionLocker> m)
{ stacksMutex_ = m;}
/**
......@@ -131,7 +133,7 @@ private /*fields*/:
EntryPoint entryPoint_;
bool blindMode_;
bool nextCallInto_;
CriticalSectionLocker * stacksMutex_;
ShPtr<CriticalSectionLocker> stacksMutex_;
DebuggingInteractionHandler * debugHandler_;
ExternalModuleLoadFunctor * externalModuleLoad_;
ExternalModuleResetFunctor * externalModuleReset_;
......@@ -857,9 +859,9 @@ void KumirVM::reset()
}
Kumir::Files::setConsoleInputBuffer(consoleInputBuffer_);
Kumir::Files::setConsoleOutputBuffer(consoleOutputBuffer_);
if (stacksMutex_ == nullptr) {
if (! stacksMutex_) {
static CriticalSectionLocker dummyMutex;
stacksMutex_ = &dummyMutex;
stacksMutex_.reset(&dummyMutex);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment