From 3c97baefefcd9b4a16bf4b0a4f74fb509db97035 Mon Sep 17 00:00:00 2001 From: Bill Stoddard Date: Fri, 24 Aug 2001 17:01:21 +0000 Subject: [PATCH] Eliminate a cache_handle leak. cache_handle is now allocated out of the 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 | 12 +++++++----- modules/experimental/mod_cache.h | 2 +- modules/experimental/mod_mem_cache.c | 13 ++----------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/modules/experimental/cache_storage.c b/modules/experimental/cache_storage.c index 8184db5f4d..2f4580324a 100644 --- a/modules/experimental/cache_storage.c +++ b/modules/experimental/cache_storage.c @@ -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 diff --git a/modules/experimental/mod_cache.h b/modules/experimental/mod_cache.h index 7d04dd11d5..d7f465b04e 100644 --- a/modules/experimental/mod_cache.h +++ b/modules/experimental/mod_cache.h @@ -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)) diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index 9c353af5be..df1cd7c11d 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -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; } -- 2.50.1