stas 2003/12/09 17:46:29
Modified: xs/Apache/Filter Apache__Filter.h src/modules/perl modperl_filter.c . Changes Log: fix a memory leak when $filter->ctx is used Revision Changes Path 1.33 +13 -0 modperl-2.0/xs/Apache/Filter/Apache__Filter.h Index: Apache__Filter.h =================================================================== RCS file: /home/cvs/modperl-2.0/xs/Apache/Filter/Apache__Filter.h,v retrieving revision 1.32 retrieving revision 1.33 diff -u -u -r1.32 -r1.33 --- Apache__Filter.h 9 May 2003 03:33:01 -0000 1.32 +++ Apache__Filter.h 10 Dec 2003 01:46:28 -0000 1.33 @@ -156,6 +156,19 @@ modperl_filter_ctx_t *ctx = (modperl_filter_ctx_t *)(filter->ctx); if (data != Nullsv) { + if (ctx->data) { + if (SvOK(ctx->data) && SvREFCNT(ctx->data)) { + /* release the previously stored SV so we don't leak + * an SV */ + SvREFCNT_dec(ctx->data); + } + } + +#ifdef USE_ITHREADS + if (!ctx->perl) { + ctx->perl = aTHX; + } +#endif ctx->data = SvREFCNT_inc(data); } 1.75 +36 -0 modperl-2.0/src/modules/perl/modperl_filter.c Index: modperl_filter.c =================================================================== RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v retrieving revision 1.74 retrieving revision 1.75 diff -u -u -r1.74 -r1.75 --- modperl_filter.c 22 Nov 2003 10:21:53 -0000 1.74 +++ modperl_filter.c 10 Dec 2003 01:46:28 -0000 1.75 @@ -223,6 +223,27 @@ /* generic filter routines */ +/* all ap_filter_t filter cleanups should go here */ +static apr_status_t modperl_filter_f_cleanup(void *data) +{ + ap_filter_t *f = (ap_filter_t *)data; + modperl_filter_ctx_t *ctx = (modperl_filter_ctx_t *)(f->ctx); + + /* mod_perl filter ctx cleanup */ + if (ctx->data){ +#ifdef USE_ITHREADS + dTHXa(ctx->perl); +#endif + if (SvOK(ctx->data) && SvREFCNT(ctx->data)) { + SvREFCNT_dec(ctx->data); + ctx->data = NULL; + } + ctx->perl = NULL; + } + + return APR_SUCCESS; +} + modperl_filter_t *modperl_filter_new(ap_filter_t *f, apr_bucket_brigade *bb, modperl_filter_mode_e mode, @@ -854,6 +875,11 @@ f = addfunc(name, (void*)ctx, NULL, c); + /* ap_filter_t filter cleanup */ + apr_pool_cleanup_register(c->pool, (void *)f, + modperl_filter_f_cleanup, + apr_pool_cleanup_null); + if (handlers[i]->attrs & MP_FILTER_HAS_INIT_HANDLER && handlers[i]->next) { int status = modperl_run_filter_init( @@ -952,6 +978,11 @@ f = addfunc(name, (void*)ctx, r, r->connection); + /* ap_filter_t filter cleanup */ + apr_pool_cleanup_register(r->pool, (void *)f, + modperl_filter_f_cleanup, + apr_pool_cleanup_null); + if (handlers[i]->attrs & MP_FILTER_HAS_INIT_HANDLER && handlers[i]->next) { int status = modperl_run_filter_init( @@ -1033,6 +1064,11 @@ ctx->handler = handler; f = addfunc(name, (void*)ctx, r, c); + + /* ap_filter_t filter cleanup */ + apr_pool_cleanup_register(pool, (void *)f, + modperl_filter_f_cleanup, + apr_pool_cleanup_null); /* has to resolve early so we can check for init functions */ if (!modperl_mgv_resolve(aTHX_ handler, pool, handler->name, TRUE)) { 1.274 +2 -0 modperl-2.0/Changes Index: Changes =================================================================== RCS file: /home/cvs/modperl-2.0/Changes,v retrieving revision 1.273 retrieving revision 1.274 diff -u -u -r1.273 -r1.274 --- Changes 8 Dec 2003 19:34:16 -0000 1.273 +++ Changes 10 Dec 2003 01:46:29 -0000 1.274 @@ -12,6 +12,8 @@ =item 1.99_12-dev +fix a memory leak when $filter->ctx is used [Stas] + fix buglet on Win32 (and potentially other non-Unix platforms) where not all files were being installed under a relative Apache2 subdirectory when MP_INST_APACHE2 was specified [Randy Kobes].