applypatch: Release FD when explicitly calling close.

We use android::base::unique_fd() to avoid leaking FD. We also want to
call close (or ota_close) to explicitly check the close result. When
combining the two together, we need to release the unique_fd to avoid
closing the same FD twice.

Bug: 33034669
Test: Trigger applypatch with install-recovery.sh.
Change-Id: I1a4f5d5fba7a23ef98d8bd7b7b07e87ae6f705c5
(cherry picked from commit 48cf770471ef53fbf0a1837196220862a0bdb18d)
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index 9b84fa1..41a8d58 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -210,7 +210,7 @@
     printf("fsync of \"%s\" failed: %s\n", filename, strerror(errno));
     return -1;
   }
-  if (ota_close(fd) != 0) {
+  if (ota_close(fd.release()) != 0) {
     printf("close of \"%s\" failed: %s\n", filename, strerror(errno));
     return -1;
   }
@@ -268,7 +268,7 @@
       printf("failed to sync to %s: %s\n", partition, strerror(errno));
       return -1;
     }
-    if (ota_close(fd) != 0) {
+    if (ota_close(fd.release()) != 0) {
       printf("failed to close %s: %s\n", partition, strerror(errno));
       return -1;
     }
@@ -287,7 +287,7 @@
     } else {
       printf("  caches dropped\n");
     }
-    ota_close(dc);
+    ota_close(dc.release());
     sleep(1);
 
     // Verify.
@@ -339,7 +339,7 @@
     return -1;
   }
 
-  if (ota_close(fd) == -1) {
+  if (ota_close(fd.release()) == -1) {
     printf("error closing %s: %s\n", partition, strerror(errno));
     return -1;
   }
@@ -782,7 +782,7 @@
         printf("failed to fsync file \"%s\": %s\n", tmp_target_filename.c_str(), strerror(errno));
         result = 1;
       }
-      if (ota_close(output_fd) != 0) {
+      if (ota_close(output_fd.release()) != 0) {
         printf("failed to close file \"%s\": %s\n", tmp_target_filename.c_str(), strerror(errno));
         result = 1;
       }