CloseArchive() to free memory when OpenArchive fails.

Bug: 26962895
Change-Id: I42418eee320ddae857b42572690316c53f638e85
(cherry picked from commit 722072d65abb1b9fa709f5c7ae8afd98ef5ab7af)
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 4591498..0eba77c 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -462,13 +462,21 @@
         }
 
         ZipArchiveHandle handle = nullptr;
+        void* cookie = nullptr;
+        auto zip_guard = make_scope_guard([&]() {
+          if (cookie != nullptr) {
+            EndIteration(cookie);
+          }
+          if (handle != nullptr) {
+            CloseArchive(handle);
+          }
+        });
         if (OpenArchive(resolved_path, &handle) != 0) {
           DL_WARN("Warning: unable to open zip archive: %s", resolved_path);
           continue;
         }
 
         // Check if zip-file has a dir with entry_path name
-        void* cookie = nullptr;
         std::string prefix_str = entry_path + "/";
         ZipString prefix(prefix_str.c_str());
 
@@ -489,13 +497,6 @@
           continue;
         }
 
-        auto zip_guard = make_scope_guard([&]() {
-          if (cookie != nullptr) {
-            EndIteration(cookie);
-          }
-          CloseArchive(handle);
-        });
-
         resolved_paths->push_back(std::string(resolved_path) + kZipFileSeparator + entry_path);
       }
     }
@@ -1481,6 +1482,7 @@
 
   if (OpenArchiveFd(fd, "", handle) != 0) {
     // invalid zip-file (?)
+    CloseArchive(handle);
     close(fd);
     return false;
   }