From 1759b18a7048205e20da9ba59fa601b9c6af8796 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 21 Jan 2019 10:53:22 +0100 Subject: [PATCH] Fix a memory leak Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginJuce.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/backend/plugin/CarlaPluginJuce.cpp b/source/backend/plugin/CarlaPluginJuce.cpp index e8f4c03ec..174520e82 100644 --- a/source/backend/plugin/CarlaPluginJuce.cpp +++ b/source/backend/plugin/CarlaPluginJuce.cpp @@ -272,8 +272,10 @@ public: } else { + uint8_t* const dataCompat = (uint8_t*)std::malloc(dataSize + 160); + CARLA_SAFE_ASSERT_RETURN(dataCompat != nullptr,); + carla_stdout("NOTE: Loading plugin state in Carla compatibiity mode"); - uint8_t* const dataCompat = new uint8_t[dataSize + 160]; std::memset(dataCompat, 0, 160); std::memcpy(dataCompat+160, data, dataSize); @@ -286,8 +288,12 @@ public: set[3] = fxbSwap(1); set[39] = fxbSwap(dataSize); - const ScopedSingleProcessLocker spl(this, true); - fInstance->setStateInformation(dataCompat, static_cast(dataSize+160)); + { + const ScopedSingleProcessLocker spl(this, true); + fInstance->setStateInformation(dataCompat, static_cast(dataSize+160)); + } + + std::free(dataCompat); } #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)