A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix memory leak with Epub object getting orphaned

+22 -10
+3 -1
src/main.cpp
··· 51 51 } 52 52 53 53 Serial.println("Failed to load epub"); 54 - free(epub); 54 + delete epub; 55 55 return nullptr; 56 56 } 57 57 ··· 122 122 } else { 123 123 exitScreen(); 124 124 enterNewScreen(new FullScreenMessageScreen(renderer, "Failed to load epub", REGULAR, false, false)); 125 + delay(2000); 126 + onGoHome(); 125 127 } 126 128 } 127 129
+13 -3
src/screens/EpubReaderScreen.cpp
··· 14 14 } 15 15 16 16 void EpubReaderScreen::onEnter() { 17 + if (!epub) { 18 + return; 19 + } 20 + 17 21 sectionMutex = xSemaphoreCreateMutex(); 18 22 19 23 epub->setupCacheDir(); ··· 42 46 43 47 void EpubReaderScreen::onExit() { 44 48 xSemaphoreTake(sectionMutex, portMAX_DELAY); 45 - vTaskDelete(displayTaskHandle); 49 + if (displayTaskHandle) { 50 + vTaskDelete(displayTaskHandle); 51 + displayTaskHandle = nullptr; 52 + } 46 53 vSemaphoreDelete(sectionMutex); 47 - displayTaskHandle = nullptr; 48 54 sectionMutex = nullptr; 55 + delete section; 56 + section = nullptr; 57 + delete epub; 58 + epub = nullptr; 49 59 } 50 60 51 61 void EpubReaderScreen::handleInput(const Input input) { ··· 141 151 section->setupCacheDir(); 142 152 if (!section->persistPageDataToSD()) { 143 153 Serial.println("Failed to persist page data to SD"); 144 - free(section); 154 + delete section; 145 155 section = nullptr; 146 156 xSemaphoreGive(sectionMutex); 147 157 return;
-4
src/screens/EpubReaderScreen.h
··· 26 26 public: 27 27 explicit EpubReaderScreen(EpdRenderer* renderer, Epub* epub, const std::function<void()>& onGoHome) 28 28 : Screen(renderer), epub(epub), onGoHome(onGoHome) {} 29 - ~EpubReaderScreen() override { 30 - free(section); 31 - free(epub); 32 - } 33 29 void onEnter() override; 34 30 void onExit() override; 35 31 void handleInput(Input input) override;
+6 -2
src/screens/FileSelectionScreen.cpp
··· 32 32 void FileSelectionScreen::onEnter() { 33 33 basepath = "/"; 34 34 loadFiles(); 35 + selectorIndex = 0; 35 36 36 37 // Trigger first update 37 38 updateRequired = true; ··· 45 46 } 46 47 47 48 void FileSelectionScreen::onExit() { 48 - vTaskDelete(displayTaskHandle); 49 - displayTaskHandle = nullptr; 49 + if (displayTaskHandle) { 50 + vTaskDelete(displayTaskHandle); 51 + displayTaskHandle = nullptr; 52 + } 53 + files.clear(); 50 54 } 51 55 52 56 void FileSelectionScreen::handleInput(const Input input) {