mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17: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");
|
Serial.println("Failed to load epub");
|
||||||
free(epub);
|
delete epub;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +122,8 @@ void onSelectEpubFile(const std::string& path) {
|
|||||||
} else {
|
} else {
|
||||||
exitScreen();
|
exitScreen();
|
||||||
enterNewScreen(new FullScreenMessageScreen(renderer, "Failed to load epub", REGULAR, false, false));
|
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() {
|
void EpubReaderScreen::onEnter() {
|
||||||
|
if (!epub) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sectionMutex = xSemaphoreCreateMutex();
|
sectionMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
epub->setupCacheDir();
|
epub->setupCacheDir();
|
||||||
@ -42,10 +46,16 @@ void EpubReaderScreen::onEnter() {
|
|||||||
|
|
||||||
void EpubReaderScreen::onExit() {
|
void EpubReaderScreen::onExit() {
|
||||||
xSemaphoreTake(sectionMutex, portMAX_DELAY);
|
xSemaphoreTake(sectionMutex, portMAX_DELAY);
|
||||||
vTaskDelete(displayTaskHandle);
|
if (displayTaskHandle) {
|
||||||
|
vTaskDelete(displayTaskHandle);
|
||||||
|
displayTaskHandle = nullptr;
|
||||||
|
}
|
||||||
vSemaphoreDelete(sectionMutex);
|
vSemaphoreDelete(sectionMutex);
|
||||||
displayTaskHandle = nullptr;
|
|
||||||
sectionMutex = nullptr;
|
sectionMutex = nullptr;
|
||||||
|
delete section;
|
||||||
|
section = nullptr;
|
||||||
|
delete epub;
|
||||||
|
epub = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EpubReaderScreen::handleInput(const Input input) {
|
void EpubReaderScreen::handleInput(const Input input) {
|
||||||
@ -141,7 +151,7 @@ void EpubReaderScreen::renderPage() {
|
|||||||
section->setupCacheDir();
|
section->setupCacheDir();
|
||||||
if (!section->persistPageDataToSD()) {
|
if (!section->persistPageDataToSD()) {
|
||||||
Serial.println("Failed to persist page data to SD");
|
Serial.println("Failed to persist page data to SD");
|
||||||
free(section);
|
delete section;
|
||||||
section = nullptr;
|
section = nullptr;
|
||||||
xSemaphoreGive(sectionMutex);
|
xSemaphoreGive(sectionMutex);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -26,10 +26,6 @@ class EpubReaderScreen final : public Screen {
|
|||||||
public:
|
public:
|
||||||
explicit EpubReaderScreen(EpdRenderer* renderer, Epub* epub, const std::function<void()>& onGoHome)
|
explicit EpubReaderScreen(EpdRenderer* renderer, Epub* epub, const std::function<void()>& onGoHome)
|
||||||
: Screen(renderer), epub(epub), onGoHome(onGoHome) {}
|
: Screen(renderer), epub(epub), onGoHome(onGoHome) {}
|
||||||
~EpubReaderScreen() override {
|
|
||||||
free(section);
|
|
||||||
free(epub);
|
|
||||||
}
|
|
||||||
void onEnter() override;
|
void onEnter() override;
|
||||||
void onExit() override;
|
void onExit() override;
|
||||||
void handleInput(Input input) override;
|
void handleInput(Input input) override;
|
||||||
|
|||||||
@ -32,6 +32,7 @@ void FileSelectionScreen::loadFiles() {
|
|||||||
void FileSelectionScreen::onEnter() {
|
void FileSelectionScreen::onEnter() {
|
||||||
basepath = "/";
|
basepath = "/";
|
||||||
loadFiles();
|
loadFiles();
|
||||||
|
selectorIndex = 0;
|
||||||
|
|
||||||
// Trigger first update
|
// Trigger first update
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -45,8 +46,11 @@ void FileSelectionScreen::onEnter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileSelectionScreen::onExit() {
|
void FileSelectionScreen::onExit() {
|
||||||
vTaskDelete(displayTaskHandle);
|
if (displayTaskHandle) {
|
||||||
displayTaskHandle = nullptr;
|
vTaskDelete(displayTaskHandle);
|
||||||
|
displayTaskHandle = nullptr;
|
||||||
|
}
|
||||||
|
files.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSelectionScreen::handleInput(const Input input) {
|
void FileSelectionScreen::handleInput(const Input input) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user