From: William Lallemand Date: Fri, 24 Nov 2017 13:33:54 +0000 (+0100) Subject: BUG/MEDIUM: cache: free ressources in chn_end_analyze X-Git-Tag: v1.8.0~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49dc048c25d04357bcdebdefd197b47666bf14bc;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: cache: free ressources in chn_end_analyze Upon an aborted HTTP connection, or an error, the filter cache does not decrement the refcount and does not free the allocated ressources. --- diff --git a/src/cache.c b/src/cache.c index 87c1da75fa..e277bec85c 100644 --- a/src/cache.c +++ b/src/cache.c @@ -139,6 +139,35 @@ cache_store_chn_start_analyze(struct stream *s, struct filter *filter, struct ch return 1; } +static int +cache_store_chn_end_analyze(struct stream *s, struct filter *filter, struct channel *chn) +{ + struct cache_st *st = filter->ctx; + struct cache *cache = filter->config->conf; + struct shared_context *shctx = shctx_ptr(cache); + + if (!(chn->flags & CF_ISRESP)) + return 1; + + /* Everything should be released in the http_end filter, but we need to do it + * there too, in case of errors */ + + if (st && st->first_block) { + + shctx_lock(shctx); + shctx_row_dec_hot(shctx, st->first_block); + shctx_unlock(shctx); + + } + if (st) { + pool_free2(pool2_cache_st, st); + filter->ctx = NULL; + } + + return 1; +} + + static int cache_store_http_headers(struct stream *s, struct filter *filter, struct http_msg *msg) { @@ -892,6 +921,7 @@ struct flt_ops cache_ops = { /* Handle channels activity */ .channel_start_analyze = cache_store_chn_start_analyze, + .channel_end_analyze = cache_store_chn_end_analyze, /* Filter HTTP requests and responses */ .http_headers = cache_store_http_headers,