From b965cac48114ab33466e450b91e0b1697be5c790 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Tue, 14 Mar 2017 20:09:53 +0100 Subject: [PATCH] Projectkk2glider/issue 4099 leaks (#4617) * Re #4099: memory leaks on model select screen fixed [Horus] * Re #4099: memory leak in wizard background image [Horus] --- radio/src/gui/480x272/model_select.cpp | 5 ++++- radio/src/storage/modelslist.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/480x272/model_select.cpp b/radio/src/gui/480x272/model_select.cpp index 3b0edc59b..9998d32ac 100644 --- a/radio/src/gui/480x272/model_select.cpp +++ b/radio/src/gui/480x272/model_select.cpp @@ -125,6 +125,7 @@ uint8_t getWizardCount() } } } + f_closedir(&dir); return wizCnt; } @@ -192,7 +193,8 @@ bool menuModelWizard(event_t event) strcpy(&wizpath[sizeof(WIZARD_PATH)], fno.fname); strcpy(&wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)], "/icon.png"); lcdDrawText(x + 10, WIZARD_TEXT_Y, fno.fname); - lcd->drawBitmap(x, WIZARD_ICON_Y, BitmapBuffer::load(wizpath)); + BitmapBuffer * background = BitmapBuffer::load(wizpath); + lcd->drawBitmap(x, WIZARD_ICON_Y, background); if(wizidx == wizardSelected ) { if (wizardSelected < 5) { lcdDrawRect(x, WIZARD_ICON_Y, 85, 130, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX); @@ -207,6 +209,7 @@ bool menuModelWizard(event_t event) } } } + delete background; } } } diff --git a/radio/src/storage/modelslist.h b/radio/src/storage/modelslist.h index fbd175bc1..e920d70b4 100644 --- a/radio/src/storage/modelslist.h +++ b/radio/src/storage/modelslist.h @@ -36,6 +36,13 @@ class ModelCell strncpy(this->modelFilename, name, sizeof(this->modelFilename)); } + ~ModelCell() + { + if (buffer) { + delete buffer; + } + } + const BitmapBuffer * getBuffer() { if (!buffer) { @@ -100,6 +107,14 @@ class ModelsCategory: public std::list strncpy(this->name, name, sizeof(this->name)); } + ~ModelsCategory() + { + for (std::list::iterator it = begin(); it != end(); ++it) { + delete *it; + } + } + + ModelCell * addModel(const char * name) { ModelCell * result = new ModelCell(name);