summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-02-11 15:55:58 +0100
committerDavid Robillard <d@drobilla.net>2017-02-12 11:11:14 +0100
commitb6b8f7b3371c6c27055ec1fba970de56dd057a01 (patch)
tree9e8bd44a1c4196e962f87c0c68e8f0dc09554806
parent740b0b7874c0393a14354eb447d689bc30da3eac (diff)
downloadingen-b6b8f7b3371c6c27055ec1fba970de56dd057a01.tar.gz
ingen-b6b8f7b3371c6c27055ec1fba970de56dd057a01.tar.bz2
ingen-b6b8f7b3371c6c27055ec1fba970de56dd057a01.zip
Fix memory leaks
-rw-r--r--src/server/DirectDriver.hpp4
-rw-r--r--src/server/Engine.cpp14
-rw-r--r--src/server/JackDriver.cpp11
-rw-r--r--src/server/RunContext.cpp14
-rw-r--r--src/server/RunContext.hpp4
5 files changed, 30 insertions, 17 deletions
diff --git a/src/server/DirectDriver.hpp b/src/server/DirectDriver.hpp
index 339d9987..186ea5f0 100644
--- a/src/server/DirectDriver.hpp
+++ b/src/server/DirectDriver.hpp
@@ -35,7 +35,9 @@ public:
, _seq_size(seq_size)
{}
- virtual ~DirectDriver() {}
+ virtual ~DirectDriver() {
+ _ports.clear_and_dispose([](EnginePort* p) { delete p; });
+ }
virtual void activate() {}
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index 1a9d82b0..e70d5522 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -151,7 +151,13 @@ Engine::~Engine()
_post_processor->process();
}
+ delete _atom_interface;
+
+ // Delete run contexts
+ _quit_flag = true;
+ _tasks_available.notify_all();
for (RunContext* ctx : _run_contexts) {
+ ctx->join();
delete ctx;
}
for (Raul::RingBuffer* ring : _notifications) {
@@ -176,9 +182,11 @@ Engine::~Engine()
delete _pre_processor;
delete _post_processor;
delete _undo_stack;
+ delete _redo_stack;
delete _block_factory;
delete _control_bindings;
delete _broadcaster;
+ delete _sync_worker;
delete _worker;
delete _maid;
@@ -227,8 +235,10 @@ Engine::pending_notifications()
bool
Engine::wait_for_tasks()
{
- std::unique_lock<std::mutex> lock(_tasks_mutex);
- _tasks_available.wait(lock);
+ if (!_quit_flag) {
+ std::unique_lock<std::mutex> lock(_tasks_mutex);
+ _tasks_available.wait(lock);
+ }
return !_quit_flag;
}
diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp
index fb672ffa..c03bf42c 100644
--- a/src/server/JackDriver.cpp
+++ b/src/server/JackDriver.cpp
@@ -71,17 +71,10 @@ JackDriver::JackDriver(Engine& engine)
&_forge, &engine.world()->uri_map().urid_map_feature()->urid_map);
}
-struct PortDisposer {
- void operator()(EnginePort* port) { delete port; }
-};
-
JackDriver::~JackDriver()
{
deactivate();
- _ports.clear_and_dispose(PortDisposer());
-
- if (_client)
- jack_client_close(_client);
+ _ports.clear_and_dispose([](EnginePort* p) { delete p; });
}
bool
@@ -178,7 +171,7 @@ void
JackDriver::deactivate()
{
if (_is_activated) {
- _flag = true;
+ _flag = true;
_is_activated = false;
_sem.timed_wait(1000);
diff --git a/src/server/RunContext.cpp b/src/server/RunContext.cpp
index 1ab73605..81b59552 100644
--- a/src/server/RunContext.cpp
+++ b/src/server/RunContext.cpp
@@ -75,9 +75,6 @@ RunContext::RunContext(const RunContext& copy)
, _realtime(copy._realtime)
{}
-RunContext::~RunContext()
-{}
-
bool
RunContext::must_notify(const PortImpl* port) const
{
@@ -159,6 +156,17 @@ RunContext::set_priority(int priority)
}
void
+RunContext::join()
+{
+ if (_thread) {
+ if (_thread->joinable()) {
+ _thread->join();
+ }
+ delete _thread;
+ }
+}
+
+void
RunContext::run()
{
while (_engine.wait_for_tasks()) {
diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp
index d2f24f8d..099ce70f 100644
--- a/src/server/RunContext.hpp
+++ b/src/server/RunContext.hpp
@@ -67,8 +67,6 @@ public:
*/
RunContext(const RunContext& parent);
- virtual ~RunContext();
-
/** Return true iff the given port should broadcast its value.
*
* Whether or not broadcasting is actually done is a per-client property,
@@ -123,6 +121,8 @@ public:
void set_priority(int priority);
void set_rate(SampleCount rate) { _rate = rate; }
+ void join();
+
inline Engine& engine() const { return _engine; }
inline Task* task() const { return _task; }
inline unsigned id() const { return _id; }