Skip to content

Commit

Permalink
Merge pull request #761 from Daft-Freak/list_diles-DIR-leak
Browse files Browse the repository at this point in the history
Fix DIR leak in blit::list_files
  • Loading branch information
Gadgetoid authored Mar 10, 2022
2 parents 8eded36 + d17872f commit 730cb34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions 32blit-pico/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ uint32_t get_file_length(void *fh) {
}

void list_files(const std::string &path, std::function<void(blit::FileInfo &)> callback) {
auto dir = new DIR();
DIR dir;

if(f_opendir(dir, path.c_str()) != FR_OK)
if(f_opendir(&dir, path.c_str()) != FR_OK)
return;

FILINFO ent;

while(f_readdir(dir, &ent) == FR_OK && ent.fname[0]) {
while(f_readdir(&dir, &ent) == FR_OK && ent.fname[0]) {
blit::FileInfo info;

info.name = ent.fname;
Expand All @@ -187,7 +187,7 @@ void list_files(const std::string &path, std::function<void(blit::FileInfo &)> c
callback(info);
}

f_closedir(dir);
f_closedir(&dir);
}

bool file_exists(const std::string &path) {
Expand Down
8 changes: 4 additions & 4 deletions 32blit-stm32/Src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ void list_files(const std::string &path, std::function<void(blit::FileInfo &)> c
if(g_usbManager.GetType() == USBManager::usbtMSC)
return;

auto dir = new DIR();
DIR dir;

if(f_opendir(dir, path.c_str()) != FR_OK)
if(f_opendir(&dir, path.c_str()) != FR_OK)
return;

FILINFO ent;

while(f_readdir(dir, &ent) == FR_OK && ent.fname[0]) {
while(f_readdir(&dir, &ent) == FR_OK && ent.fname[0]) {
blit::FileInfo info;

info.name = ent.fname;
Expand All @@ -131,7 +131,7 @@ void list_files(const std::string &path, std::function<void(blit::FileInfo &)> c
callback(info);
}

f_closedir(dir);
f_closedir(&dir);
}

bool file_exists(const std::string &path) {
Expand Down

0 comments on commit 730cb34

Please sign in to comment.