From 3ed720dcd3b906a2774597c8331c108fc2d8ace9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 25 Apr 2021 21:58:24 +0200 Subject: [PATCH] App: [skip ci] fix memory leaks: Found two memory leaks in class Enumeration * method tearDown() always ignored to free the memory of the first element * assignment operator didn't call tearDown() when needed --- src/App/Enumeration.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/App/Enumeration.cpp b/src/App/Enumeration.cpp index f9a346c55c..bda0899206 100644 --- a/src/App/Enumeration.cpp +++ b/src/App/Enumeration.cpp @@ -84,8 +84,8 @@ void Enumeration::tearDown(void) char **plEnums = (char **)_EnumArray; // Delete C Strings first - while (*(plEnums++) != NULL) { - free(*plEnums); + while (*plEnums != NULL) { + free(*(plEnums++)); } delete [] _EnumArray; @@ -288,9 +288,16 @@ bool Enumeration::isValid(void) const Enumeration & Enumeration::operator=(const Enumeration &other) { + if (this == &other) + return *this; + if (other._ownEnumArray) { setEnums(other.getEnumVector()); } else { + if (isValid() && _ownEnumArray) { + tearDown(); + } + _EnumArray = other._EnumArray; }