Skip to content

Commit 11bd039

Browse files
committed
AudioSourceSD: memory leak
1 parent 43f161d commit 11bd039

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/AudioTools/Disk/AudioSourceSD.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,19 @@ class AudioSourceSD : public AudioSource {
8282
}
8383

8484
virtual Stream *selectStream(int index) override {
85-
LOGI("selectStream: %d", index);
86-
idx_pos = index;
87-
file_name = idx[index];
88-
if (file_name==nullptr) return nullptr;
89-
LOGI("Using file %s", file_name);
90-
file = SD.open(file_name);
91-
return file ? &file : nullptr;
85+
LOGI("selectStream SD: %d", index);
86+
if (index > -1) { // avoid invalid position
87+
idx_pos = index;
88+
}
89+
return selectStream(idx[idx_pos]);
9290
}
9391

9492
virtual Stream *selectStream(const char *path) override {
9593
file.close();
94+
if (path == nullptr) {
95+
LOGE("Filename is null")
96+
return nullptr;
97+
}
9698
file = SD.open(path);
9799
file_name = file.name();
98100
LOGI("-> selectStream: %s", path);

0 commit comments

Comments
 (0)