Re: $r->document_root

[prev] [thread] [next] [Date index for 2005/02/19]

From: Stas Bekman
Subject: Re: $r->document_root
Date: 02:02 on 19 Feb 2005
Stas Bekman wrote:
> Cahill, Earl wrote:
> [...]
> 
>> Second, I couldn't get this
>>
>> $r->document_root(hostname2docroot($r->hostname));
[...]
> It's a bug. This patch which will go in shortly fixes it:
[...]
> +        conf->ap_document_root = apr_pstrdup(r->pool, 
> SvPV_nolen(new_root));
[...]
> before it just happened to work in certain situation. Since the value 
> wasn't copied, if you have changed the scalar after assigning it, it'd 
> affect the doc root in an unpredictable way. You've detected it since 
> you've passed a value returned by another function. In that case it 
> returns a TMP scalar which is special, as perl reuses it whenever the 
> function is re-invoked. That's why you weren't getting it to work. This 
> patch does a proper copying of that string.

I was just adding a note to the API method doc saying:

   it's important to mention that at the end of each request where
   you modify this setting you absolutely must restore it to its
   original value.

but it doesn't work, since the resetting will be allocated from the 
request pool, which will go away at the end of the request, leaving the 
data corrupted.

So unless I miss something we have two options:

1) nuke that method completely

2) either provide a new method that restores the data using a preallocated 
string from the server pool or do that internally in the server

3) or change $r->document_root method to accept the pool object and leave 
the users the headache of figuring out what they want to do. This is 
because if they use $r->pool and expect it stick beyond that request it 
won't work. If however they pass $r->server->pool and they do that on each 
request they leak memory.

Comments?

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(message missing)

$r->document_root
Cahill, Earl 23:14 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:21 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:26 on 14 Feb 2005

RE: $r->document_root
Cahill, Earl 20:43 on 15 Feb 2005

Re: $r->document_root
Geoffrey Young 21:10 on 15 Feb 2005

Re: $r->document_root
Stas Bekman 01:48 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 02:02 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 13:54 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 17:21 on 19 Feb 2005

Re: $r->document_root
Joe Schaefer 14:12 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 05:26 on 20 Feb 2005

Re: $r->document_root
Stas Bekman 01:29 on 21 Feb 2005

Re: $r->document_root
Joe Schaefer 02:38 on 21 Feb 2005

Re: $r->document_root
Stas Bekman 02:43 on 21 Feb 2005

Generated at 12:48 on 22 Feb 2005 by mariachi v0.52