You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Greg Ames <gr...@raleigh.ibm.com> on 2000/07/05 18:04:28 UTC

[PATCH] mod_mmap_static - memory leak

Change mod_mmap_static to use pools which are guaranteed to be defined at config command
parsing time.   It was using a global which wasn't explicitly set to a valid pool until
post config time (after it was used).  So on the first pass the "pool" was 0, causing
ap_palloc to malloc storage which was never cleaned up.  On the second pass, it used the
config pool from the first pass, which it got away with, but is living dangerously.

Greg

Index: mod_mmap_static.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/modules/experimental/mod_mmap_static.c,v
retrieving revision 1.16
diff -u -d -b -w -r1.16 mod_mmap_static.c
--- mod_mmap_static.c   2000/07/03 16:36:56     1.16
+++ mod_mmap_static.c   2000/07/05 15:46:43
@@ -136,7 +136,6 @@
     char *filename;
     ap_finfo_t finfo;
 } a_file;
-ap_pool_t *context;

 typedef struct {
     ap_array_header_t *files;
@@ -174,7 +173,7 @@
     a_file tmp;
     ap_file_t *fd = NULL;

-    if (ap_stat(&tmp.finfo, filename, context) != APR_SUCCESS) {
+    if (ap_stat(&tmp.finfo, filename, NULL) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server,
            "mmap_static: unable to stat(%s), skipping", filename);
        return NULL;
@@ -184,12 +183,14 @@
            "mmap_static: %s isn't a regular file, skipping", filename);
        return NULL;
     }
-    if (ap_open(&fd, filename, APR_READ, APR_OS_DEFAULT, context) != APR_SUCCESS) {
+    if (ap_open(&fd, filename, APR_READ, APR_OS_DEFAULT, cmd->temp_pool)
+        != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server,
            "mmap_static: unable to open(%s, O_RDONLY), skipping", filename);
        return NULL;
     }
-    if (ap_mmap_create(&tmp.mm, fd, 0, tmp.finfo.size, context) != APR_SUCCESS) {
+    if (ap_mmap_create(&tmp.mm, fd, 0, tmp.finfo.size, cmd->pool)
+        != APR_SUCCESS) {
        int save_errno = errno;
        ap_close(fd);
        errno = save_errno;
@@ -224,7 +225,6 @@
     a_file *elts;
     int nelts;

-    context = p;
     /* sort the elements of the main_server, by filename */
     sconf = ap_get_module_config(s->module_config, &mmap_static_module);
     elts = (a_file *)sconf->files->elts;