about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-10-06 21:48:35 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-10-06 22:18:24 +0530
commit27b6edbb090f736b101f569620d8ad0e7217ddf8 (patch)
tree805e2f3be96c59a4972d065b7513492c020014ba
parent3234a31b489707f19ec6d4c9909af06f20ddb901 (diff)
downloadglibc-27b6edbb090f736b101f569620d8ad0e7217ddf8.tar.gz
glibc-27b6edbb090f736b101f569620d8ad0e7217ddf8.tar.xz
glibc-27b6edbb090f736b101f569620d8ad0e7217ddf8.zip
support: Also return fd when it is 0
The fd validity check in open_dev_null checks if fd > 0, which would
lead to a leaked fd if it is == 0.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
-rw-r--r--support/support-open-dev-null-range.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c
index 80d9dba504..66a8504105 100644
--- a/support/support-open-dev-null-range.c
+++ b/support/support-open-dev-null-range.c
@@ -40,16 +40,16 @@ increase_nofile (void)
 static int
 open_dev_null (int flags, mode_t mode)
 {
- int fd = open64 ("/dev/null", flags, mode);
- if (fd > 0)
-   return fd;
+  int fd = open64 ("/dev/null", flags, mode);
+  if (fd >= 0)
+    return fd;
 
- if (fd < 0 && errno != EMFILE)
-   FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
+  if (fd < 0 && errno != EMFILE)
+    FAIL_EXIT1 ("open64 (\"/dev/null\", 0x%x, 0%o): %m", flags, mode);
 
- increase_nofile ();
+  increase_nofile ();
 
- return xopen ("/dev/null", flags, mode);
+  return xopen ("/dev/null", flags, mode);
 }
 
 struct range