From e8325b39c47e6fbf7c8c1e31f9026870d9520af5 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 25 Apr 2019 13:03:10 +0200 Subject: fix maxfd being zero If _SC_OPEN_MAX is available then maxfd was zero initialized and never set to the value from sysconf. This leads to segfaults with free(): invalid size introduced by commit 7cafb0e84550035fe671662c293122be975065ca. Signed-off-by: Sven Nierlein --- plugins/utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'plugins/utils.c') diff --git a/plugins/utils.c b/plugins/utils.c index ee620133..348ec022 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -678,3 +678,19 @@ char *sperfdata_int (const char *label, return data; } + +int +open_max (void) +{ + errno = 0; + if (maxfd > 0) + return(maxfd); + + if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { + if (errno == 0) + maxfd = DEFAULT_MAXFD; /* it's indeterminate */ + else + die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); + } + return(maxfd); +} -- cgit v1.2.3