Commit a54763a4 authored by Bill Stoddard's avatar Bill Stoddard
Browse files

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
parent a845a790
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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))
+2 −11
Original line number Diff line number Diff line
@@ -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;
}