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

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