Blame SOURCES/xinetd-2.3.14-realloc-remove.patch

01101d
diff -rup xinetd-2.3.14/xinetd/defs.h xinetd-2.3.14-mod/xinetd/defs.h
01101d
--- xinetd-2.3.14/xinetd/defs.h	2012-01-18 14:22:20.811100158 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/defs.h	2012-01-18 13:32:46.000000000 +0100
01101d
@@ -114,11 +114,7 @@ union xsockaddr {
01101d
  * constants for limiting ps.rws.fd_list 
01101d
  */
01101d
 
01101d
-#ifdef HAVE_POLL
01101d
-#define INIT_POLLFDS                 4096
01101d
-/* FIXME: not used */
01101d
-#define MAX_POLLFDS                  16384
01101d
-#endif
01101d
+#define MAX_FDS                      4096
01101d
 
01101d
 /*
01101d
  * When explicit values are given for enum's, that is because the structures 
01101d
diff -rup xinetd-2.3.14/xinetd/init.c xinetd-2.3.14-mod/xinetd/init.c
01101d
--- xinetd-2.3.14/xinetd/init.c	2012-01-18 14:22:20.779100171 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/init.c	2012-01-18 14:07:34.000000000 +0100
01101d
@@ -151,7 +151,7 @@ static void set_fd_limit(void)
01101d
    }
01101d
 
01101d
    if ( rl.rlim_max == RLIM_INFINITY ) 
01101d
-      rl.rlim_max = FD_SETSIZE;
01101d
+      rl.rlim_max = MAX_FDS;
01101d
 
01101d
    ps.ros.max_descriptors = rl.rlim_max ;
01101d
 #else      /* ! RLIMIT_NOFILE */
01101d
@@ -283,12 +283,12 @@ static void init_rw_state( void )
01101d
    ps.rws.descriptors_free = ps.ros.max_descriptors - DESCRIPTORS_RESERVED ;
01101d
 
01101d
 #ifdef HAVE_POLL
01101d
-   ps.rws.pfds_allocated = INIT_POLLFDS ;
01101d
+   ps.rws.pfds_allocated = ps.ros.max_descriptors ;
01101d
    ps.rws.pfd_array = (struct pollfd *) 
01101d
                       malloc( sizeof( struct pollfd ) * ps.rws.pfds_allocated ) ;
01101d
    if ( ps.rws.pfd_array == NULL ) 
01101d
    {
01101d
-      out_of_memory(func);
01101d
+      out_of_memory(func) ;
01101d
       exit( 1 ) ;
01101d
    }
01101d
    ps.rws.pfds_last = 0 ;
01101d
diff -rup xinetd-2.3.14/xinetd/redirect.c xinetd-2.3.14-mod/xinetd/redirect.c
01101d
--- xinetd-2.3.14/xinetd/redirect.c	2012-01-18 14:22:20.780100170 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/redirect.c	2012-01-18 12:22:08.000000000 +0100
01101d
@@ -149,7 +149,7 @@ void redir_handler( struct server *serp
01101d
 #ifdef HAVE_POLL
01101d
 #define REDIR_DESCRIP_INDEX 0
01101d
 #define REDIR_SERVER_INDEX 1
01101d
-      pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),INIT_POLLFDS);
01101d
+      pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),MAX_FDS);
01101d
       if (pfd_array == NULL)
01101d
       {
01101d
          msg( LOG_ERR, func, "Cannot allocate memory for file descriptors!\n");
01101d
diff -rup xinetd-2.3.14/xinetd/service.c xinetd-2.3.14-mod/xinetd/service.c
01101d
--- xinetd-2.3.14/xinetd/service.c	2012-01-18 14:22:20.812100157 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/service.c	2012-01-18 14:07:27.000000000 +0100
01101d
@@ -114,10 +114,6 @@ struct service *svc_make_special( struct
01101d
 
01101d
 void svc_free( struct service *sp )
01101d
 {
01101d
-#ifdef HAVE_POLL
01101d
-   *SVC_POLLFD( sp ) = ps.rws.pfd_array[--ps.rws.pfds_last] ;
01101d
-#endif /* HAVE_POLL */
01101d
-
01101d
    sc_free( SVC_CONF(sp) ) ;
01101d
    CLEAR( *sp ) ;
01101d
    FREE_SVC( sp ) ;
01101d
@@ -332,20 +328,10 @@ status_e svc_activate( struct service *s
01101d
    }
01101d
 
01101d
 #ifdef HAVE_POLL
01101d
-   if ( ps.rws.pfds_last >= ps.rws.pfds_allocated )
01101d
+   if ( ps.rws.descriptors_free <= 0 )
01101d
    {
01101d
-     int pos;
01101d
-     ps.rws.pfds_allocated += INIT_POLLFDS;
01101d
-     struct pollfd *tmp = (struct pollfd *)realloc( ps.rws.pfd_array,
01101d
-       ps.rws.pfds_allocated*sizeof(struct pollfd));
01101d
-     if ( tmp == NULL )
01101d
-     {
01101d
-       out_of_memory( func );
01101d
-       return( FAILED );
01101d
-     }
01101d
-     ps.rws.pfd_array = tmp;
01101d
-     memset(&ps.rws.pfd_array[ps.rws.pfds_last], 0, (ps.rws.pfds_allocated-
01101d
-       ps.rws.pfds_last)*sizeof(struct pollfd));
01101d
+     msg(LOG_ERR, func, "Maximum number of services reached") ;
01101d
+     return( FAILED ) ;
01101d
    }
01101d
    if ( sp->svc_pfd_index >= 0 )
01101d
    {
01101d
diff -rup xinetd-2.3.14/xinetd/tcpint.c xinetd-2.3.14-mod/xinetd/tcpint.c
01101d
--- xinetd-2.3.14/xinetd/tcpint.c	2012-01-18 14:22:20.782100169 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/tcpint.c	2012-01-18 13:30:22.000000000 +0100
01101d
@@ -93,7 +93,7 @@ static void si_mux(void)
01101d
 #ifdef HAVE_POLL
01101d
    struct pollfd        *pfd_array;
01101d
    int                   pfds_last = 0;
01101d
-   int                   pfds_allocated = INIT_POLLFDS;
01101d
+   int                   pfds_allocated = MAX_FDS;
01101d
 #else
01101d
    fd_set                     socket_mask ;
01101d
    int                        mask_max ;
01101d
@@ -102,7 +102,7 @@ static void si_mux(void)
01101d
    const char                *func = "si_mux" ;
01101d
 
01101d
 #ifdef HAVE_POLL
01101d
-   pfd_array = calloc(sizeof(struct pollfd),INIT_POLLFDS);
01101d
+   pfd_array = calloc(sizeof(struct pollfd),MAX_FDS);
01101d
    pfd_array[ pfds_last ].fd = INT_REMOTE( ip ) ;
01101d
    pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT;
01101d
 #else
01101d
diff -rup xinetd-2.3.14/xinetd/udpint.c xinetd-2.3.14-mod/xinetd/udpint.c
01101d
--- xinetd-2.3.14/xinetd/udpint.c	2012-01-18 14:22:20.783100169 +0100
01101d
+++ xinetd-2.3.14-mod/xinetd/udpint.c	2012-01-18 12:22:00.000000000 +0100
01101d
@@ -103,14 +103,14 @@ static void di_mux(void)
01101d
 #ifdef HAVE_POLL
01101d
    struct pollfd        *pfd_array;
01101d
    int                   pfds_last = 0;
01101d
-   int                   pfds_allocated = INIT_POLLFDS;
01101d
+   int                   pfds_allocated = MAX_FDS;
01101d
 #else
01101d
    fd_set                     socket_mask ;
01101d
    int                        mask_max ;
01101d
 #endif
01101d
 
01101d
 #ifdef HAVE_POLL
01101d
-   pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),INIT_POLLFDS);
01101d
+   pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),MAX_FDS);
01101d
    pfd_array[ pfds_last ].fd = INT_REMOTE( ip );
01101d
    pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT;
01101d
 #else