From f6cd305277322c211369e49d958f1b8ee79783ff Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Fri, 1 Apr 2011 10:36:42 +0000 Subject: [PATCH] Found some leaking file descriptors while looking at ast_FD_SETSIZE dead code. (issue #18969) Reported by: oej Patches: 20110315__issue18969__14.diff.txt uploaded by tilghman (license 14) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@312285 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/select.h | 3 ++- main/asterisk.c | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/asterisk/select.h b/include/asterisk/select.h index 773b0a54ed..5ba189a102 100644 --- a/include/asterisk/select.h +++ b/include/asterisk/select.h @@ -37,8 +37,9 @@ extern unsigned int ast_FD_SETSIZE; #if !defined(HAVE_VARIABLE_FDSET) && defined(CONFIGURE_RAN_AS_ROOT) #define ast_fdset fd_set #else +#define ast_FDMAX 32768 typedef struct { - TYPEOF_FD_SET_FDS_BITS fds_bits[4096 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */ + TYPEOF_FD_SET_FDS_BITS fds_bits[ast_FDMAX / 8 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */ } ast_fdset; #undef FD_ZERO diff --git a/main/asterisk.c b/main/asterisk.c index 58bccfcbbc..523e997790 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2932,6 +2932,7 @@ int main(int argc, char *argv[]) fd2 = (l.rlim_cur > sizeof(readers) * 8 ? sizeof(readers) * 8 : l.rlim_cur) - 1; if (dup2(fd, fd2) < 0) { ast_log(LOG_WARNING, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno)); + close(fd); break; } @@ -2940,9 +2941,12 @@ int main(int argc, char *argv[]) if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) { ast_log(LOG_WARNING, "Maximum select()able file descriptor is %d\n", FD_SETSIZE); } + ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; + close(fd); + close(fd2); } while (0); #elif defined(HAVE_VARIABLE_FDSET) - ast_FD_SETSIZE = l.rlim_cur; + ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */ if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP)) -- 2.47.2