Skip to content

Commit

Permalink
Fix memory leak in power juice
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Sep 19, 2021
1 parent a73b4cf commit 88ba2e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions plugins/PowerJuice/PowerJuicePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ START_NAMESPACE_DISTRHO
PowerJuicePlugin::PowerJuicePlugin()
: Plugin(paramCount, 1, 0) // 1 program, 0 states
{
std::memset(&RMSStack, 0, sizeof(RMSStack));
std::memset(&lookaheadStack, 0, sizeof(lookaheadStack));

// set default values
loadProgram(0);

Expand All @@ -35,8 +38,8 @@ PowerJuicePlugin::PowerJuicePlugin()

PowerJuicePlugin::~PowerJuicePlugin()
{
free(lookaheadStack.data);
free(RMSStack.data);
std::free(RMSStack.data);
std::free(lookaheadStack.data);
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -208,9 +211,11 @@ void PowerJuicePlugin::loadProgram(uint32_t index)


kFloatRMSStackCount = 400.0f/44100.0f*getSampleRate();
std::free(RMSStack.data);
RMSStack.data = (float*) calloc(kFloatRMSStackCount, sizeof(float));

kFloatLookaheadStackCount = 800.0f/44100.0f*getSampleRate();
std::free(lookaheadStack.data);
lookaheadStack.data = (float*) calloc(kFloatLookaheadStackCount, sizeof(float));

refreshSkip= 300.0f/44100.0f*getSampleRate();
Expand Down
9 changes: 7 additions & 2 deletions plugins/PowerJuiceX2/PowerJuiceX2Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ START_NAMESPACE_DISTRHO
PowerJuiceX2Plugin::PowerJuiceX2Plugin()
: Plugin(paramCount, 1, 0) // 1 program, 0 states
{
std::memset(&RMSStack, 0, sizeof(RMSStack));
std::memset(&lookaheadStack, 0, sizeof(lookaheadStack));

// set default values
loadProgram(0);

Expand All @@ -35,8 +38,8 @@ PowerJuiceX2Plugin::PowerJuiceX2Plugin()

PowerJuiceX2Plugin::~PowerJuiceX2Plugin()
{
free(lookaheadStack.data);
free(RMSStack.data);
std::free(RMSStack.data);
std::free(lookaheadStack.data);
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -208,9 +211,11 @@ void PowerJuiceX2Plugin::loadProgram(uint32_t index)


kFloatRMSStackCount = 400.0f/44100.0f*getSampleRate();
std::free(RMSStack.data);
RMSStack.data = (float*) calloc(kFloatRMSStackCount, sizeof(float));

kFloatLookaheadStackCount = 800.0f/44100.0f*getSampleRate();
std::free(lookaheadStack.data);
lookaheadStack.data = (float*) calloc(kFloatLookaheadStackCount, sizeof(float));

refreshSkip= 300.0f/44100.0f*getSampleRate();
Expand Down

0 comments on commit 88ba2e8

Please sign in to comment.