Do not munmap in MmapFile::~MmapFile
Having any destructor with a global variable in bionic is causing
some issues. Since we don't actually need to munmap in this case, we
remove the destructor to work around that issue.
A small class is used to still munmap during tests.
Bug: 73485611
Test: bionic unit tests
Change-Id: Ibcd45e9b1ab22d187ecfc2738bb87244250d81ea
diff --git a/libc/bionic/grp_pwd_file.cpp b/libc/bionic/grp_pwd_file.cpp
index 911daea..c17dbb7 100644
--- a/libc/bionic/grp_pwd_file.cpp
+++ b/libc/bionic/grp_pwd_file.cpp
@@ -193,10 +193,13 @@
lock_.init(false);
}
-MmapFile::~MmapFile() {
+void MmapFile::Unmap() {
if (status_ == FileStatus::Initialized) {
size_t size = end_ - start_ + 1;
munmap(const_cast<char*>(start_), size);
+ status_ = FileStatus::Uninitialized;
+ start_ = nullptr;
+ end_ = nullptr;
}
}