From 377917c5d0be42218d468e209d33540d1c71ccee Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Tue, 8 Jan 2013 15:58:02 -0500 Subject: [PATCH] base fetch: fix two memory leaks, one severe and one potential --- src/ngx_base_fetch.h | 2 +- src/ngx_pagespeed.cc | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ngx_base_fetch.h b/src/ngx_base_fetch.h index 6b6322242..90561dfa2 100644 --- a/src/ngx_base_fetch.h +++ b/src/ngx_base_fetch.h @@ -115,7 +115,7 @@ class NgxBaseFetch : public AsyncFetch { int pipe_fd_; // How many active references there are to this fetch. Starts at two, // decremented once when Done() is called and once when Release() is called. - bool references_; + int references_; pthread_mutex_t mutex_; DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch); diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index a17d02a28..0286ec0a7 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -1063,7 +1063,9 @@ ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch) { } // Handles its own deletion. We need to call Release() when we're done with - // it, and call Done() on the associated proxy fetch. + // it, and call Done() on the associated parent (Proxy or Resource) fetch. If + // we fail before creating the associated fetch then we need to call Done() on + // the BaseFetch ourselves. ctx->base_fetch = new net_instaweb::NgxBaseFetch( r, file_descriptors[1], net_instaweb::RequestContextPtr(new net_instaweb::RequestContext( @@ -1073,6 +1075,7 @@ ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch) { net_instaweb::RewriteOptions* custom_options; bool ok = ps_determine_options(r, ctx, &custom_options, &url); if (!ok) { + ctx->base_fetch->Done(false); // Not passed to Proxy/ResourceFetch yet. ps_release_request_context(ctx); return CreateRequestContext::kError; } @@ -1089,6 +1092,7 @@ ps_create_request_context(ngx_http_request_t* r, bool is_resource_fetch) { } if (!options->enabled()) { + ctx->base_fetch->Done(false); // Not passed to Proxy/ResourceFetch yet. ps_release_request_context(ctx); return CreateRequestContext::kPagespeedDisabled; }