Merge "Use unique_fd for usableProgram" into main am: 908ca9e9d8

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3372419

Change-Id: Ic4a542720c9ce691f2121f8885d03b4c123b5398
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
index 3c4bc6e..a31445a 100644
--- a/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
+++ b/bpf/syscall_wrappers/include/BpfSyscallWrappers.h
@@ -28,6 +28,7 @@
 namespace bpf {
 
 using ::android::base::borrowed_fd;
+using ::android::base::unique_fd;
 
 inline uint64_t ptr_to_u64(const void * const x) {
     return (uint64_t)(uintptr_t)x;
@@ -182,10 +183,8 @@
 }
 
 inline bool usableProgram(const char* pathname) {
-    int fd = retrieveProgram(pathname);
-    bool ok = (fd >= 0);
-    if (ok) close(fd);
-    return ok;
+    unique_fd fd(retrieveProgram(pathname));
+    return fd.ok();
 }
 
 inline int attachProgram(bpf_attach_type type, const borrowed_fd& prog_fd,