On 08/08/2018 09:39 AM, Aron Barath wrote:
> * lib/fdleak.c (get_max_fd): add guard around the fd_limit variable

Thanks for the patch.

I'd favor to give that variable a better scope instead of adding another
#if/#endif block.  I'll push the attached in your name unless you have
objections.

Thanks & have a nice day,
Berny

>From 3801c55e1f151d7e1edaaee375c55b1edfe9e69c Mon Sep 17 00:00:00 2001
From: Aron Barath <baratha...@caesar.elte.hu>
Date: Wed, 8 Aug 2018 09:39:42 +0200
Subject: [PATCH] fdleak.c: avoid unused variable on platforms lacking
 getrlimit

* lib/fdleak.c (get_max_fd): Move definition of the fd_limit variable
into the HAVE_GETRLIMIT block.

Copyright-paperwork-exempt: Yes
---
 lib/fdleak.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/fdleak.c b/lib/fdleak.c
index 38ff8360..818c0fbe 100644
--- a/lib/fdleak.c
+++ b/lib/fdleak.c
@@ -109,7 +109,6 @@ get_proc_max_fd (void)
 static int
 get_max_fd (void)
 {
-  struct rlimit fd_limit;
   long open_max;
 
   open_max = get_proc_max_fd ();
@@ -122,13 +121,16 @@ get_max_fd (void)
 
   /* We assume if RLIMIT_NOFILE is defined, all the related macros are, too. */
 #if defined HAVE_GETRLIMIT && defined RLIMIT_NOFILE
-  if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit))
-    {
-      if (fd_limit.rlim_cur == RLIM_INFINITY)
-	return open_max;
-      else
-	return (int) fd_limit.rlim_cur;
-    }
+  {
+    struct rlimit fd_limit;
+    if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit))
+      {
+	if (fd_limit.rlim_cur == RLIM_INFINITY)
+	  return open_max;
+	else
+	  return (int) fd_limit.rlim_cur;
+      }
+  }
 #endif
   /* cannot determine the limit's value */
   return open_max;
-- 
2.18.0

Reply via email to