From 2a8c80557f43fa0b23fc8996779c1cd62b14df91 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 10 Feb 2022 13:22:34 +0000 Subject: [PATCH] Fix some memory leaks Signed-off-by: falkTX --- carla | 2 +- dpf | 2 +- src/CardinalUI.cpp | 19 ++++++++++++++----- src/override/Window.cpp | 3 +-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/carla b/carla index 782f7f6..b1ecb33 160000 --- a/carla +++ b/carla @@ -1 +1 @@ -Subproject commit 782f7f64a7e1a2e197c3e75c90f1d71c8e5b925c +Subproject commit b1ecb33a5ec8d24a98a93ed038713a6da6cc9701 diff --git a/dpf b/dpf index 0de149b..4ebd02b 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 0de149b8cbdc59d74273b7fc8b2193b0885afc33 +Subproject commit 4ebd02b0ee1a019d46bcd065e21dc68f8af80031 diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index 96b5863..9958f2a 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -15,6 +15,7 @@ * For a full copy of the GNU General Public License see the LICENSE file. */ +#include #include #include #include @@ -291,8 +292,11 @@ public: rack::window::WindowSetPluginUI(context->window, this); - if (context->scene->menuBar != nullptr) - context->scene->removeChild(context->scene->menuBar); + if (rack::widget::Widget* const menuBar = context->scene->menuBar) + { + context->scene->removeChild(menuBar); + delete menuBar; + } context->scene->menuBar = rack::app::createMenuBar(getApp().isStandalone()); context->scene->addChildBelow(context->scene->menuBar, context->scene->rackScroll); @@ -336,9 +340,14 @@ public: context->nativeWindowId = 0; - rack::widget::Widget* const menuBar = context->scene->menuBar; - context->scene->menuBar = nullptr; - context->scene->removeChild(menuBar); + if (rack::widget::Widget* const menuBar = context->scene->menuBar) + { + context->scene->removeChild(menuBar); + delete menuBar; + } + + context->scene->menuBar = rack::app::createMenuBar(); + context->scene->addChildBelow(context->scene->menuBar, context->scene->rackScroll); rack::window::WindowSetPluginUI(context->window, nullptr); diff --git a/src/override/Window.cpp b/src/override/Window.cpp index 3ed6cad..ed70a55 100644 --- a/src/override/Window.cpp +++ b/src/override/Window.cpp @@ -92,9 +92,8 @@ void Font::loadFile(const std::string& filename, NVGcontext* vg) { // Transfer ownership of font data to font object uint8_t* data = system::readFile(filename, &size); // Don't use nvgCreateFont because it doesn't properly handle UTF-8 filenames on Windows. - handle = nvgCreateFontMem(vg, name.c_str(), data, size, 0); + handle = nvgCreateFontMem(vg, name.c_str(), data, size, 1); if (handle < 0) { - std::free(data); throw Exception("Failed to load font %s", filename.c_str()); } INFO("Loaded font %s", filename.c_str());