Check overflows in c-tor instead of doing it in d-tor

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Id3b17a79732155b4e469c43c764afef1dfc59057
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 79c3ac5..b8dd216 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -462,13 +462,13 @@
   if (ref_count_++ == 0) {
     protect_data(PROT_READ | PROT_WRITE);
   }
-}
 
-ProtectedDataGuard::~ProtectedDataGuard() {
   if (ref_count_ == 0) { // overflow
     __libc_fatal("Too many nested calls to dlopen()");
   }
+}
 
+ProtectedDataGuard::~ProtectedDataGuard() {
   if (--ref_count_ == 0) {
     protect_data(PROT_READ);
   }