From bd34ee943e1041cfff7d4bd896bb4bb2c09a546a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 23 Feb 2008 19:51:43 +0000 Subject: Plug several memory leaks. Reduce Patchage memory consumption (shrink (stupid) alsa thread stack size). git-svn-id: http://svn.drobilla.net/lad/patchage@1161 a436a847-0d15-0410-975c-d299462d15a1 --- src/AlsaDriver.cpp | 19 +++++++++++++------ src/GladeFile.hpp | 2 -- src/Patchage.cpp | 4 ++++ src/Widget.hpp | 5 ++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 22d1924..3b2703b 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -60,7 +60,11 @@ AlsaDriver::attach(bool /*launch_daemon*/) snd_seq_set_client_name(_seq, "Patchage"); - ret = pthread_create(&_refresh_thread, NULL, &AlsaDriver::refresh_main, this); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 50000); + + ret = pthread_create(&_refresh_thread, &attr, &AlsaDriver::refresh_main, this); if (ret) cerr << "Couldn't start refresh thread" << endl; @@ -466,17 +470,17 @@ AlsaDriver::_refresh_main() { // "Heavily influenced" from alsa-patch-bay // (C) 2002 Robert Ham, released under GPL + + if (!create_refresh_port()) { + cerr << "Could not create Alsa listen port. Auto refreshing will not work." << endl; + return; + } int ret; int nfds = snd_seq_poll_descriptors_count(_seq, POLLIN); struct pollfd* pfds = new struct pollfd[nfds]; unsigned short* revents = new unsigned short[nfds]; - if (!create_refresh_port()) { - cerr << "Could not create Alsa listen port. Auto refreshing will not work." << endl; - return; - } - snd_seq_poll_descriptors(_seq, pfds, nfds, POLLIN); while (true) { @@ -527,6 +531,9 @@ AlsaDriver::_refresh_main() } } } + + delete[] pfds; + delete[] revents; } diff --git a/src/GladeFile.hpp b/src/GladeFile.hpp index cc0954c..ad334f1 100644 --- a/src/GladeFile.hpp +++ b/src/GladeFile.hpp @@ -27,8 +27,6 @@ class GladeFile { public: static Glib::RefPtr open(const std::string& base_name) { - Glib::RefPtr xml; - // Check for the .glade file in current directory std::string glade_filename = std::string("./").append(base_name).append(".glade"); std::ifstream fs(glade_filename.c_str()); diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 3d124a2..4519ede 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -262,6 +262,10 @@ Patchage::~Patchage() delete _lash_driver; #endif delete _state_manager; + + _about_win.destroy(); + _messages_win.destroy(); + _main_win.destroy(); } diff --git a/src/Widget.hpp b/src/Widget.hpp index ea8a218..4fea89a 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -27,7 +27,9 @@ public: Widget(Glib::RefPtr xml, const std::string& name) { xml->get_widget(name.c_str(), _me); } - + + void destroy() { delete _me; } + W* get() { return _me; } const W* get() const { return _me; } W* operator->() { return _me; } @@ -38,5 +40,6 @@ public: private: W* _me; }; + #endif // WIDGET_HPP -- cgit v1.2.1