OSDN Git Service

bpf: close the file descriptor after probe inside getHostCPUNameForBPF
authorYonghong Song <yhs@fb.com>
Wed, 23 Aug 2017 16:24:31 +0000 (16:24 +0000)
committerYonghong Song <yhs@fb.com>
Wed, 23 Aug 2017 16:24:31 +0000 (16:24 +0000)
Signed-off-by: Yonghong Song <yhs@fb.com>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311567 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Host.cpp

index aa1c4ae..ad16b02 100644 (file)
@@ -300,7 +300,11 @@ StringRef sys::detail::getHostCPUNameForBPF() {
   attr.license = (uint64_t)"DUMMY";
 
   int fd = syscall(321 /* __NR_bpf */, 5 /* BPF_PROG_LOAD */, &attr, sizeof(attr));
-  return (fd > 0) ? "v2" : "v1";
+  if (fd >= 0) {
+    close(fd);
+    return "v2";
+  }
+  return "v1";
 #endif
 }