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;
   }
 }
 
diff --git a/libc/bionic/grp_pwd_file.h b/libc/bionic/grp_pwd_file.h
index 93dd852..048cd82 100644
--- a/libc/bionic/grp_pwd_file.h
+++ b/libc/bionic/grp_pwd_file.h
@@ -38,12 +38,12 @@
 class MmapFile {
  public:
   MmapFile(const char* filename);
-  ~MmapFile();
 
   template <typename Line>
   bool FindById(uid_t uid, Line* line);
   template <typename Line>
   bool FindByName(const char* name, Line* line);
+  void Unmap();
 
   DISALLOW_COPY_AND_ASSIGN(MmapFile);
 
@@ -73,6 +73,9 @@
 
   bool FindById(uid_t id, passwd_state_t* passwd_state);
   bool FindByName(const char* name, passwd_state_t* passwd_state);
+  void Unmap() {
+    mmap_file_.Unmap();
+  }
 
   DISALLOW_COPY_AND_ASSIGN(PasswdFile);
 
@@ -86,6 +89,9 @@
 
   bool FindById(gid_t id, group_state_t* group_state);
   bool FindByName(const char* name, group_state_t* group_state);
+  void Unmap() {
+    mmap_file_.Unmap();
+  }
 
   DISALLOW_COPY_AND_ASSIGN(GroupFile);