Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251ASSERT_OK(env_->NewRandomAccessFile(file_path, &file));252CheckCloseOnExecDoesNotLeakFDs(open_fds);253delete file;255for (int i = 0; i < kReadOnlyFileLimit; i++) {256delete mmapped_files[i];257}258ASSERT_OK(env_->DeleteFile(file_path));259}261TEST(EnvPosixTest, TestCloseOnExecWritableFile) {262std::unordered_set<int> open_fds;263GetOpenFileDescriptors(&open_fds);265std::string test_dir;266ASSERT_OK(env_->GetTestDirectory(&test_dir));267std::string file_path = test_dir + "/close_on_exec_writable.txt";268ASSERT_OK(WriteStringToFile(env_, "0123456789", file_path));270leveldb::WritableFile* file = nullptr;271ASSERT_OK(env_->NewWritableFile(file_path, &file));272CheckCloseOnExecDoesNotLeakFDs(open_fds);273delete file;275ASSERT_OK(env_->DeleteFile(file_path));276}278TEST(EnvPosixTest, TestCloseOnExecAppendableFile) {279std::unordered_set<int> open_fds;280GetOpenFileDescriptors(&open_fds);282std::string test_dir;283ASSERT_OK(env_->GetTestDirectory(&test_dir));284std::string file_path = test_dir + "/close_on_exec_appendable.txt";285ASSERT_OK(WriteStringToFile(env_, "0123456789", file_path));287leveldb::WritableFile* file = nullptr;288ASSERT_OK(env_->NewAppendableFile(file_path, &file));289CheckCloseOnExecDoesNotLeakFDs(open_fds);290delete file;292ASSERT_OK(env_->DeleteFile(file_path));293}295TEST(EnvPosixTest, TestCloseOnExecLockFile) {296std::unordered_set<int> open_fds;297GetOpenFileDescriptors(&open_fds);299std::string test_dir;300ASSERT_OK(env_->GetTestDirectory(&test_dir));301std::string file_path = test_dir + "/close_on_exec_lock.txt";302ASSERT_OK(WriteStringToFile(env_, "0123456789", file_path));304leveldb::FileLock* lock = nullptr;305ASSERT_OK(env_->LockFile(file_path, &lock));306CheckCloseOnExecDoesNotLeakFDs(open_fds);307ASSERT_OK(env_->UnlockFile(lock));309ASSERT_OK(env_->DeleteFile(file_path));310}312TEST(EnvPosixTest, TestCloseOnExecLogger) {313std::unordered_set<int> open_fds;314GetOpenFileDescriptors(&open_fds);316std::string test_dir;317ASSERT_OK(env_->GetTestDirectory(&test_dir));318std::string file_path = test_dir + "/close_on_exec_logger.txt";319ASSERT_OK(WriteStringToFile(env_, "0123456789", file_path));321leveldb::Logger* file = nullptr;322ASSERT_OK(env_->NewLogger(file_path, &file));323CheckCloseOnExecDoesNotLeakFDs(open_fds);324delete file;326ASSERT_OK(env_->DeleteFile(file_path));327}329#endif // HAVE_O_CLOEXEC331} // namespace leveldb333int main(int argc, char** argv) {334#if HAVE_O_CLOEXEC335// Check if we're invoked as a helper program, or as the test suite.336for (int i = 1; i < argc; ++i) {337if (!std::strcmp(argv[i], kTestCloseOnExecSwitch)) {338return TestCloseOnExecHelperMain(argv[i + 1]);339}340}342// Save argv[0] early, because googletest may modify argv.343GetArgvZero()->assign(argv[0], argv[0] + std::strlen(argv[0]) + 1);344#endif // HAVE_O_CLOEXEC346// All tests currently run with the same read-only file limits.347leveldb::EnvPosixTest::SetFileLimits(leveldb::kReadOnlyFileLimit,348leveldb::kMMapLimit);349return leveldb::test::RunAllTests();350}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.