Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gloo/common/linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static std::vector<std::string> listDir(const std::string& path) {
continue;
}
result.push_back(dirent->d_name);
errno = 0;
}
GLOO_ENFORCE(errno == 0, strerror(errno));
auto rv = closedir(dirp);
Expand Down
11 changes: 11 additions & 0 deletions gloo/test/linux_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/

#include <errno.h>

#include <functional>
#include <thread>
#include <vector>
Expand Down Expand Up @@ -45,6 +47,15 @@ TEST_F(LinuxTest, PCIDistance) {
}
}

// Verify that listDir (called by pciDevices) tolerates stale errno left by
// prior allocations. Before the fix, vector::push_back inside the readdir
// loop could leave errno=ENOMEM from a transient mmap failure, causing
// GLOO_ENFORCE(errno == 0) to crash after readdir returns NULL at EOF.
TEST_F(LinuxTest, PciDevicesDoesNotCrashWithStaleErrno) {
errno = ENOMEM;
ASSERT_NO_THROW(pciDevices(kPCIClassNetwork));
}

} // namespace
} // namespace test
} // namespace gloo