Skip to content

Memory Leak in Keypad Widget Destructor #46

@davidwagerksl

Description

@davidwagerksl

Our Application contains several screens, of which some contain keypads.

During internal testing, we received feedback that the entering and exiting a screen with a keypad an arbitrary number of times led to a crash (As described by the tester, in reality it was entering the TLB Refill Exception handler).
While debugging this fault, we noticed that immediately before entering the exception handler there were calls being returned a NULL pointer from LE_MALLOC.

After digging into the memory management inside the library, we eventually discovered that while idle there was no change to the capacity of fixedHeap[2], though every time we entered and exited a screen with a keypad, the capacity would be reduced but never recovered. Looking at the callstack, we discovered that it LE_MALLOCs for every row.

for(r = 0; r < rows; ++r)
{
newCells[r] = LE_MALLOC(cols * sizeof(leKeyPadCell));
memset(newCells[r], 0, cols * sizeof(leKeyPadCell));
}

Although the destructor only LE_FREEs _this->cells

static void destructor(leKeyPadWidget* _this)
{
LE_FREE(_this->cells);
_leWidget_Destructor((leWidget*)_this);
}

In order to get around this for our application, we have amended the destructor as follows

static void destructor(leKeyPadWidget* _this)
{
+   for (int r = 0; r < _this->rows; ++r)
+   {
+        LE_FREE(_this->cells[r]);
+   }
   LE_FREE(_this->cells);

   _leWidget_Destructor((leWidget*)_this);
}

This has resolved the issue for us. Hopefully this can be reproduced and fixed for future versions of the GFX library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions