]> granicus.if.org Git - apache/commitdiff
Eliminate a cache_handle leak. cache_handle is now allocated out of the
authorBill Stoddard <stoddard@apache.org>
Fri, 24 Aug 2001 17:01:21 +0000 (17:01 +0000)
committerBill Stoddard <stoddard@apache.org>
Fri, 24 Aug 2001 17:01:21 +0000 (17:01 +0000)
request pool.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90637 13f79535-47bb-0310-9956-ffa450edef68

modules/experimental/cache_storage.c
modules/experimental/mod_cache.h
modules/experimental/mod_mem_cache.c

index 8184db5f4df30cd67312820b4224e19a6b088a04..2f4580324a1d2c9d5a63f975b4c46c0da234e63b 100644 (file)
@@ -156,7 +156,6 @@ int cache_remove_entity(request_rec *r, const char *types, cache_handle *h)
  */
 int cache_select_url(request_rec *r, const char *types, char *url)
 {
-    cache_handle *h;
     const char *next = types;
     const char *type;
     apr_status_t rv;
@@ -164,12 +163,13 @@ int cache_select_url(request_rec *r, const char *types, char *url)
                                                                           &cache_module);
 
     /* go through the cache types till we get a match */
+    cache->handle = apr_palloc(r->pool, sizeof(cache_handle));
+
     while (next) {
         type = ap_cache_tokstr(r->pool, next, &next);
-        switch ((rv = cache_run_open_entity(&h, type, url))) {
+        switch ((rv = cache_run_open_entity(cache->handle, type, url))) {
         case OK: {
             /* cool bananas! */
-            cache->handle = h;
 /*** loop through returned entities */
 /*** do freshness calculation here */
             cache->fresh = 1;
@@ -182,10 +182,12 @@ int cache_select_url(request_rec *r, const char *types, char *url)
         }
         default: {
             /* oo-er! an error */
+            cache->handle = NULL;
             return rv;
         }
         }
     }
+    cache->handle = NULL;
     return DECLINED;
 }
 
@@ -245,8 +247,8 @@ APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(cache, CACHE, int, create_entity,
                                       (cache_handle **hp, const char *type, 
                                       char *url, apr_size_t len),(hp,type,url,len),DECLINED)
 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(cache, CACHE, int, open_entity,  
-                                      (cache_handle **hp, const char *type, 
-                                      char *url),(hp,type,url),DECLINED)
+                                      (cache_handle *h, const char *type, 
+                                      char *url),(h,type,url),DECLINED)
 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(cache, CACHE, int, remove_url, 
                                     (const char *type, char *url),(type,url),OK,DECLINED)
 #if 0
index 7d04dd11d5d1a549c10faa1b98c942060a25f48c..d7f465b04e6caceec8766fae789a72290941ab84 100644 (file)
@@ -240,7 +240,7 @@ APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, create_entity,
                           (cache_handle **hp, const char *type,
                            char *url, apr_size_t len))
 APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, open_entity,  
-                          (cache_handle **hp, const char *type,
+                          (cache_handle *h, const char *type,
                            char *url))
 APR_DECLARE_EXTERNAL_HOOK(cache, CACHE, int, remove_url, 
                           (const char *type, char *url))
index 9c353af5be64a3eafd898b6f1d9e74134310137d..df1cd7c11df03a9aadd1e48b5b0e9fea14aa9b92 100644 (file)
@@ -263,10 +263,9 @@ static int create_entity(cache_handle **hp, const char *type, char *key, apr_siz
     return OK;
 }
 
-static int open_entity(cache_handle **hp, const char *type, char *key) 
+static int open_entity(cache_handle *h, const char *type, char *key) 
 {
     cache_object_t *obj;
-    cache_handle *h;
 
     /* Look up entity keyed to 'url' */
     if (strcasecmp(type, "mem")) {
@@ -284,13 +283,7 @@ static int open_entity(cache_handle **hp, const char *type, char *key)
         return DECLINED;
     }
 
-    /* Allocate the cache_handle and initialize it */
-    h = malloc(sizeof(cache_handle));
-    *hp = h;
-    if (!h) {
-        /* handle the error */
-        return DECLINED;
-    }
+    /* Initialize the cache_handle */
     h->read_body = &read_body;
     h->read_headers = &read_headers;
     h->write_body = &write_body;
@@ -319,8 +312,6 @@ static int remove_entity(cache_handle *h)
     /* Reinit the cache_handle fields? */
     h->cache_obj = NULL;
 
-    /* The caller should free the cache_handle ? */
-    free(h);
     return OK;
 }