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
This commit is contained in:
wmayer
2021-04-25 21:58:24 +02:00
parent ea96f18601
commit 3ed720dcd3

View File

@@ -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;
}