]> granicus.if.org Git - apache/commitdiff
Fix a memory leak with ap_wait_or_timeout.
authorRyan Bloom <rbb@apache.org>
Wed, 24 May 2000 00:42:01 +0000 (00:42 +0000)
committerRyan Bloom <rbb@apache.org>
Wed, 24 May 2000 00:42:01 +0000 (00:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85286 13f79535-47bb-0310-9956-ffa450edef68

include/mpm_common.h
server/mpm/dexter/dexter.c
server/mpm/mpmt_pthread/mpmt_pthread.c
server/mpm/prefork/prefork.c
server/mpm_common.c

index f693f6011cbdc3c57d99ded4badf1afeaa5a22e7..0e83e8a597935e3bfc204841c3f11d7c27469612 100644 (file)
@@ -75,7 +75,7 @@ extern "C" {
 #endif
 
 void ap_reclaim_child_processes(int terminate);
-ap_proc_t *ap_wait_or_timeout(ap_wait_t *status, ap_pool_t *p);
+void ap_wait_or_timeout(ap_wait_t *status, ap_proc_t *ret, ap_pool_t *p);
 
 #ifdef __cplusplus
 }
index b2f505d974031605f57e060b7898bc0894631965..0805cfddfabc00e87338663ec356083dffb4d93d 100644 (file)
@@ -974,19 +974,19 @@ static void server_main_loop(int remaining_children_to_start)
 {
     int child_slot;
     ap_wait_t status;
-    ap_proc_t *pid;
+    ap_proc_t pid;
     int i;
 
     while (!restart_pending && !shutdown_pending) {
-        pid = ap_wait_or_timeout(&status, pconf);
+        ap_wait_or_timeout(&status, &pid, pconf);
         
-        if (pid != NULL) {
-            process_child_status(pid, status);
+        if (pid.pid != -1) {
+            process_child_status(&pid, status);
             /* non-fatal death... note that it's gone in the child table and
              * clean out the status table. */
             child_slot = -1;
             for (i = 0; i < ap_max_daemons_limit; ++i) {
-               if (ap_child_table[i].pid == pid->pid) {
+               if (ap_child_table[i].pid == pid.pid) {
                     int j;
 
                     child_slot = i;
@@ -1009,7 +1009,7 @@ static void server_main_loop(int remaining_children_to_start)
                }
 #ifdef APR_HAS_OTHER_CHILD
            }
-           else if (ap_reap_other_child(pid, status) == 0) {
+           else if (ap_reap_other_child(&pid, status) == 0) {
                /* handled */
 #endif
            }
@@ -1021,7 +1021,7 @@ static void server_main_loop(int remaining_children_to_start)
                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, errno, 
                              ap_server_conf,
                            "long lost child came home! (pid %ld)", 
-                             (long)pid->pid);
+                             (long)pid.pid);
            }
            /* Don't perform idle maintenance when a child dies,
              * only do it when there's a timeout.  Remember only a
index d07a832530d1eb216e48416d7396b03cdb63a10a..2c4355fa093eb98eb3dfed5297cb189620509dfc 100644 (file)
@@ -1015,17 +1015,16 @@ static void server_main_loop(int remaining_children_to_start)
 {
     int child_slot;
     ap_wait_t status;
-    ap_proc_t *pid;
+    ap_proc_t pid;
     int i;
 
     while (!restart_pending && !shutdown_pending) {
-        /* this is a memory leak, but I'll fix it later. */
-        pid = ap_wait_or_timeout(&status, pconf);
+        ap_wait_or_timeout(&status, &pid, pconf);
         
-        if (pid != NULL) {
-            process_child_status(pid, status);
+        if (pid.pid != -1) {
+            process_child_status(&pid, status);
             /* non-fatal death... note that it's gone in the scoreboard. */
-            child_slot = find_child_by_pid(pid);
+            child_slot = find_child_by_pid(&pid);
             if (child_slot >= 0) {
                 ap_mpmt_pthread_force_reset_connection_status(child_slot);
                 for (i = 0; i < ap_threads_per_child; i++)
@@ -1041,7 +1040,7 @@ static void server_main_loop(int remaining_children_to_start)
                }
 #ifdef APR_HAS_OTHER_CHILD
            }
-           else if (ap_reap_other_child(pid, status) == 0) {
+           else if (ap_reap_other_child(&pid, status) == 0) {
                /* handled */
 #endif
            }
@@ -1052,7 +1051,7 @@ static void server_main_loop(int remaining_children_to_start)
                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0,
                             ap_server_conf,
                             "long lost child came home! (pid %ld)",
-                            (long)pid->pid);
+                            (long)pid.pid);
            }
            /* Don't perform idle maintenance when a child dies,
              * only do it when there's a timeout.  Remember only a
index 3da49bf35519dfa51885dbc83b68e7efb26c8a6b..7e24fcf488c3382a289d3ddfab5d2b1b69cdf56c 100644 (file)
@@ -1956,17 +1956,19 @@ int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
        int child_slot;
        ap_wait_t status;
         /* this is a memory leak, but I'll fix it later. */
-       ap_proc_t *pid = ap_wait_or_timeout(&status, pconf);
+       ap_proc_t pid;
+
+        ap_wait_or_timeout(&status, &pid, pconf);
 
        /* XXX: if it takes longer than 1 second for all our children
         * to start up and get into IDLE state then we may spawn an
         * extra child
         */
-       if (pid != NULL) {
-           process_child_status(pid, status);
+       if (pid.pid != -1) {
+           process_child_status(&pid, status);
            /* non-fatal death... note that it's gone in the scoreboard. */
            ap_sync_scoreboard_image();
-           child_slot = find_child_by_pid(pid);
+           child_slot = find_child_by_pid(&pid);
            if (child_slot >= 0) {
                 ap_prefork_force_reset_connection_status(child_slot);
                (void) ap_update_child_status(child_slot, SERVER_DEAD,
@@ -1981,7 +1983,7 @@ int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
                }
 #ifdef APR_HAS_OTHER_CHILD
            }
-           else if (ap_reap_other_child(pid, status) == 0) {
+           else if (ap_reap_other_child(&pid, status) == 0) {
                /* handled */
 #endif
            }
@@ -1992,7 +1994,7 @@ int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
                    */
                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 
                             0, ap_server_conf,
-                           "long lost child came home! (pid %d)", pid->pid);
+                           "long lost child came home! (pid %d)", pid.pid);
            }
            /* Don't perform idle maintenance when a child dies,
                * only do it when there's a timeout.  Remember only a
index 57cea6325478d5f0e77a412608bc3f78ae7b4b2e..c7c3dd1f90c05c234ab624d8c001923c58b30dec 100644 (file)
@@ -176,11 +176,10 @@ void ap_reclaim_child_processes(int terminate)
 #endif
 static int wait_or_timeout_counter;
 
-ap_proc_t *ap_wait_or_timeout(ap_wait_t *status, ap_pool_t *p)
+void ap_wait_or_timeout(ap_wait_t *status, ap_proc_t *ret, ap_pool_t *p)
 {
     struct timeval tv;
     ap_status_t rv;
-    ap_proc_t *ret = ap_pcalloc(p, sizeof(*ret));
 
     ++wait_or_timeout_counter;
     if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) {
@@ -191,20 +190,22 @@ ap_proc_t *ap_wait_or_timeout(ap_wait_t *status, ap_pool_t *p)
     }
     rv = ap_wait_all_procs(ret, status, APR_NOWAIT, p);
     if (ap_canonical_error(rv) == APR_EINTR) {
-        return NULL;
+        ret->pid = -1;
+        return;
     }
     if (rv == APR_CHILD_DONE) {
-        return ret;
+        return;
     }
 #ifdef NEED_WAITPID
     if ((ret = reap_children(status)) > 0) {
-        return ret;
+        return;
     }
 #endif
     tv.tv_sec = SCOREBOARD_MAINTENANCE_INTERVAL / 1000000;
     tv.tv_usec = SCOREBOARD_MAINTENANCE_INTERVAL % 1000000;
     ap_select(0, NULL, NULL, NULL, &tv);
-    return NULL;
+    ret->pid = -1;
+    return;
 }