diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index 504163a21f64cf75a4fd138dfb597a5c72538cd3..167a5af58d046bb948fd4666aff571bebe1e129e 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -428,7 +428,7 @@ static int my_load_module(int reload)
 	int res;
 	struct ast_config *cfg;
 	struct ast_variable *var;
-	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+	struct ast_flags config_flags = { 0 };
 	struct column *entry;
 	char *temp;
 	struct ast_str *compat;
@@ -439,6 +439,9 @@ static int my_load_module(int reload)
 	my_bool my_bool_true = 1;
 #endif
 
+	/* Cannot use a conditionally different flag, because the table layout may
+	 * have changed, which is not detectable by config file change detection,
+	 * but should still cause the configuration to be re-parsed. */
 	cfg = ast_config_load(config, config_flags);
 	if (!cfg) {
 		ast_log(LOG_WARNING, "Unable to load config for mysql CDR's: %s\n", config);
diff --git a/include/asterisk/select.h b/include/asterisk/select.h
index ac2284fc71e797a38a9b4edfa377959bc7fd8bab..a8f7c3c6077d73f4ca4020aa3f031b2bae9fd041 100644
--- a/include/asterisk/select.h
+++ b/include/asterisk/select.h
@@ -38,8 +38,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 749491515e7352c6c22328a46d0a788707595dfd..4d95466f3ddf03bde2ff02ffe34680bd13ca9af5 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3402,6 +3402,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;
 		}
 
@@ -3410,9 +3411,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))