mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-16 22:27:42 +03:00
Fix memory leak with Epub object getting orphaned
This commit is contained in:
parent
7198d943b0
commit
98c8e7e77c
@ -51,7 +51,7 @@ Epub* loadEpub(const std::string& path) {
|
||||
}
|
||||
|
||||
Serial.println("Failed to load epub");
|
||||
free(epub);
|
||||
delete epub;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -122,6 +122,8 @@ void onSelectEpubFile(const std::string& path) {
|
||||
} else {
|
||||
exitScreen();
|
||||
enterNewScreen(new FullScreenMessageScreen(renderer, "Failed to load epub", REGULAR, false, false));
|
||||
delay(2000);
|
||||
onGoHome();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,10 @@ void EpubReaderScreen::taskTrampoline(void* param) {
|
||||
}
|
||||
|
||||
void EpubReaderScreen::onEnter() {
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
|
||||
sectionMutex = xSemaphoreCreateMutex();
|
||||
|
||||
epub->setupCacheDir();
|
||||
@ -42,10 +46,16 @@ void EpubReaderScreen::onEnter() {
|
||||
|
||||
void EpubReaderScreen::onExit() {
|
||||
xSemaphoreTake(sectionMutex, portMAX_DELAY);
|
||||
vTaskDelete(displayTaskHandle);
|
||||
if (displayTaskHandle) {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
}
|
||||
vSemaphoreDelete(sectionMutex);
|
||||
displayTaskHandle = nullptr;
|
||||
sectionMutex = nullptr;
|
||||
delete section;
|
||||
section = nullptr;
|
||||
delete epub;
|
||||
epub = nullptr;
|
||||
}
|
||||
|
||||
void EpubReaderScreen::handleInput(const Input input) {
|
||||
@ -141,7 +151,7 @@ void EpubReaderScreen::renderPage() {
|
||||
section->setupCacheDir();
|
||||
if (!section->persistPageDataToSD()) {
|
||||
Serial.println("Failed to persist page data to SD");
|
||||
free(section);
|
||||
delete section;
|
||||
section = nullptr;
|
||||
xSemaphoreGive(sectionMutex);
|
||||
return;
|
||||
|
||||
@ -26,10 +26,6 @@ class EpubReaderScreen final : public Screen {
|
||||
public:
|
||||
explicit EpubReaderScreen(EpdRenderer* renderer, Epub* epub, const std::function<void()>& onGoHome)
|
||||
: Screen(renderer), epub(epub), onGoHome(onGoHome) {}
|
||||
~EpubReaderScreen() override {
|
||||
free(section);
|
||||
free(epub);
|
||||
}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput(Input input) override;
|
||||
|
||||
@ -32,6 +32,7 @@ void FileSelectionScreen::loadFiles() {
|
||||
void FileSelectionScreen::onEnter() {
|
||||
basepath = "/";
|
||||
loadFiles();
|
||||
selectorIndex = 0;
|
||||
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
@ -45,8 +46,11 @@ void FileSelectionScreen::onEnter() {
|
||||
}
|
||||
|
||||
void FileSelectionScreen::onExit() {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
if (displayTaskHandle) {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
}
|
||||
files.clear();
|
||||
}
|
||||
|
||||
void FileSelectionScreen::handleInput(const Input input) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user