Merge "Fix fd leak in android_dlopen_ext."
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 1f259e1..c5701dd 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -601,6 +601,9 @@
   }
 
   void set_fd(int fd, bool assume_ownership) {
+    if (fd_ != -1 && close_fd_) {
+      close(fd_);
+    }
     fd_ = fd;
     close_fd_ = assume_ownership;
   }