Skip to content

Commit c1b9249

Browse files
committed
AudioSources: fix memory leaks
1 parent 11bd039 commit c1b9249

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

src/AudioTools/Disk/AudioSourceSD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AudioSourceSD : public AudioSource {
7272
}
7373

7474
void end() {
75+
file.close();
7576
SD.end();
7677
is_sd_setup = false;
7778
}

src/AudioTools/Disk/AudioSourceSDFAT.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class AudioSourceSDFAT : public AudioSource {
8787
}
8888

8989
void end() {
90+
file.close();
91+
9092
if (is_sd_setup) {
9193
TRACEI();
9294
#ifdef ESP32

src/AudioTools/Disk/AudioSourceSDMMC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class AudioSourceSDMMC : public AudioSource {
5353
}
5454

5555
void end() {
56+
file.close();
5657
SD_MMC.end();
5758
is_sd_setup = false;
5859
}
@@ -65,6 +66,7 @@ class AudioSourceSDMMC : public AudioSource {
6566

6667
virtual Stream *selectStream(int index) override {
6768
LOGI("selectStream: %d", index);
69+
file.close();
6870
idx_pos = index;
6971
file_name = idx[index];
7072
if (file_name==nullptr) return nullptr;

src/AudioTools/Disk/AudioSourceSPIFFS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class AudioSourceSPIFFS : public AudioSource {
4040
}
4141

4242
void end() {
43+
file.close();
4344
SPIFFS.end();
4445
is_sd_setup = false;
4546
}
@@ -51,6 +52,7 @@ class AudioSourceSPIFFS : public AudioSource {
5152

5253
virtual Stream *selectStream(int index) override {
5354
LOGI("selectStream: %d", index);
55+
file.close();
5456
idx_pos = index;
5557
file_name = idx[index];
5658
if (file_name==nullptr) return nullptr;

src/AudioTools/Disk/AudioSourceSTD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AudioSourceSTD : public AudioSource {
3232
}
3333

3434
virtual void end() {
35+
file.close();
3536
}
3637

3738
virtual Stream *nextStream(int offset = 1) override {

src/AudioTools/Disk/AudioSourceVFS.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AudioSourceVFS : public AudioSource {
4343
}
4444

4545
virtual void end() {
46+
file.close();
4647
if (p_vfs) p_vfs->end();
4748
}
4849

@@ -64,6 +65,10 @@ class AudioSourceVFS : public AudioSource {
6465

6566
virtual Stream *selectStream(const char *path) override {
6667
file.close();
68+
if (path == nullptr) {
69+
LOGE("Filename is null")
70+
return nullptr;
71+
}
6772
assert(p_vfs != nullptr);
6873
file = p_vfs->open(path);
6974
file_name = file.name();

0 commit comments

Comments
 (0)