Skip to content

Commit

Permalink
fix memory leak for remove_all(). (#201)
Browse files Browse the repository at this point in the history
* fix memory leak for remove_all().

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
fujitatomoya authored Nov 15, 2024
1 parent 10939f9 commit ac4ee13
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/filesystem_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#endif

#include "rcutils/env.h"
#include "rcpputils/scope_exit.hpp"
#include "rcpputils/split.hpp"

namespace rcpputils
Expand Down Expand Up @@ -474,6 +475,10 @@ bool remove_all(const path & p)
return 0 == ret && false == file_options.fAnyOperationsAborted;
#else
DIR * dir = opendir(p.string().c_str());
if (dir == nullptr) {
return false;
}
RCPPUTILS_SCOPE_EXIT(closedir(dir));
struct dirent * directory_entry;
while ((directory_entry = readdir(dir)) != nullptr) {
// Make sure to not call ".." or "." entries in directory (might delete everything)
Expand All @@ -488,7 +493,6 @@ bool remove_all(const path & p)
}
}
}
closedir(dir);
// directory is empty now, call remove
rcpputils::fs::remove(p);
return !rcpputils::fs::exists(p);
Expand Down

0 comments on commit ac4ee13

Please sign in to comment.