From 9a35d9455f23f0f7055fbc6afb6845979f27cb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Andr=C3=BDsek?= Date: Mon, 30 Jun 2025 10:50:49 +0200 Subject: [PATCH] feat(SDFS): Add destructor for SD card to clean up resources (#11521) * feat(test): Enhance NVS test * fix(nvs): Remove unused Unity header and improve Serial wait loop * refactor(nvs): Extract string increment logic into a separate function * refactor(test): Format long strings in expect_exact calls for better readability * feat(SDFS): Add destructor to clean up resources --- libraries/SD/src/SD.cpp | 4 ++++ libraries/SD/src/SD.h | 1 + 2 files changed, 5 insertions(+) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 2d646276d..077a7c112 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -22,6 +22,10 @@ using namespace fs; SDFS::SDFS(FSImplPtr impl) : FS(impl), _pdrv(0xFF) {} +SDFS::~SDFS() { + end(); +} + bool SDFS::begin(uint8_t ssPin, SPIClass &spi, uint32_t frequency, const char *mountpoint, uint8_t max_files, bool format_if_empty) { if (_pdrv != 0xFF) { return true; diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index aebc781a5..d8252ee44 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -26,6 +26,7 @@ protected: public: SDFS(FSImplPtr impl); + ~SDFS(); bool begin( uint8_t ssPin = SS, SPIClass &spi = SPI, uint32_t frequency = 4000000, const char *mountpoint = "/sd", uint8_t max_files = 5, bool format_if_empty = false );