From 2b506910675d9ed8103ea7146e2994db6d957821 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 4 Oct 2019 12:08:01 +0200 Subject: [PATCH] Fixed memory leak in random_matrix and rainbow_matrix. --- src/effect_matrix.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index f12b158..e2ab435 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -144,13 +144,19 @@ MatrixEffect::MatrixEffect() { } RandomMatrixEffect::RandomMatrixEffect() { - _columns = new MatrixEffectColumn* [window->width]; - for (int i=0; iwidth; i++) _columns[i] = new RandomMatrixEffectColumn(window, random8(4), true); + // No need to initialize _columns, because that will have been done by ctor of MatrixEffect. + for (int i=0; iwidth; i++) { + delete _columns[i]; + _columns[i] = new RandomMatrixEffectColumn(window, random8(4), true); + } } RainbowMatrixEffect::RainbowMatrixEffect() { - _columns = new MatrixEffectColumn* [window->width]; - for (int i=0; iwidth; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH); + // No need to initialize _columns, because that will have been done by ctor of MatrixEffect. + for (int i=0; iwidth; i++) { + delete columns[i]; + _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH); + } } MatrixEffect::~MatrixEffect() {