Index: runtime/bin/directory_linux.cc |
diff --git a/runtime/bin/directory_linux.cc b/runtime/bin/directory_linux.cc |
index c26289cb7c53563dc1d202602b4e0b56d10f6055..0bb07e75f9f516fc53002daae5bde9d54108eca9 100644 |
--- a/runtime/bin/directory_linux.cc |
+++ b/runtime/bin/directory_linux.cc |
@@ -105,8 +105,8 @@ ListType DirectoryListingEntry::Next(DirectoryListing* listing) { |
dirent entry; |
dirent* result; |
if ((status = TEMP_FAILURE_RETRY(readdir_r(reinterpret_cast<DIR*>(lister_), |
- &entry, |
- &result))) == 0 && |
+ &entry, |
+ &result))) == 0 && |
result != NULL) { |
if (!listing->path_buffer().Add(entry.d_name)) { |
done_ = true; |
@@ -188,14 +188,18 @@ ListType DirectoryListingEntry::Next(DirectoryListing* listing) { |
return kListError; |
} |
- if (closedir(reinterpret_cast<DIR*>(lister_)) == -1) { |
- return kListError; |
- } |
- |
return kListDone; |
} |
+DirectoryListingEntry::~DirectoryListingEntry() { |
+ ResetLink(); |
+ if (lister_ != 0) { |
+ closedir(reinterpret_cast<DIR*>(lister_)); |
+ } |
+} |
+ |
+ |
void DirectoryListingEntry::ResetLink() { |
if (link_ != NULL && (parent_ == NULL || parent_->link_ != link_)) { |
delete link_; |