Author: jkaluza Date: Tue Apr 28 06:51:12 2015 New Revision: 1676417 URL: http://svn.apache.org/r1676417 Log: Initialize interp->refcnt to 1 in modperl_interp_select.
Reasoning: 1. All calls of MP_INTERPa do not increment interp->refcnt, so refcnt used to be 0 before this commit. But there is always matching MP_INTERP_PUTBACK, which calls modperl_interp_unselect which decreases the refcnt, so it was possible to get negative refcnt or crash with threaded MPMs, because reference counting has been broken. 2. modperl_interp_select increases the refcount if it finds the PerlInterp in ccfg, so it makes sense to increase it (it means set to 1) during initialization too. Otherwise the refcnt would be incremented for the caller in some cases, but wouldn't be in other. This commit fixes the crash seen on worker MPM when PerlInterp has been used by two threads and the first one freed PerlInterp during modperl_interp_unselect. Modified: perl/modperl/trunk/src/modules/perl/modperl_interp.c Modified: perl/modperl/trunk/src/modules/perl/modperl_interp.c URL: http://svn.apache.org/viewvc/perl/modperl/trunk/src/modules/perl/modperl_interp.c?rev=1676417&r1=1676416&r2=1676417&view=diff ============================================================================== --- perl/modperl/trunk/src/modules/perl/modperl_interp.c (original) +++ perl/modperl/trunk/src/modules/perl/modperl_interp.c Tue Apr 28 06:51:12 2015 @@ -460,7 +460,7 @@ modperl_interp_t *modperl_interp_select( interp = modperl_interp_get(s); MP_TRACE_i(MP_FUNC, " --> got %pp (perl=%pp)", interp, interp->perl); ++interp->num_requests; /* should only get here once per request */ - interp->refcnt = 0; + interp->refcnt = 1; /* set context (THX) for this thread */ PERL_SET_CONTEXT(interp->perl);