httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Fritsch ...@sfritsch.de>
Subject Re: Why 'apr_pstrdup' constant strings ?
Date Sat, 02 Jul 2011 07:08:16 GMT
On Tuesday 28 June 2011, Christophe JAILLET wrote:
> in several places, we are making a apr_pstrdup on a *constant*
> string. I've found at least :
>     - server/protocol.c - line 538
>     - server/protocol.c - line 615
>     - modules/proxy/proxy_util.c - line 546
>     - modules/http/http_request.c - line 200
>     - modules/generators/mod_cgid.c - line 1587
>     - modules/generators/mod_asis.c - line 73
>     - modules/generators/mod_cgi.c - line 990
>     - arch/win32/mod_isapi.c - line 897
> 
> What is the use of such a copy ?

It depends on what the string is assigned to. If the variable is not 
const, it is possible that the string is modified in place later. 
Think of e.g. replacing "/" with "\" in paths, etc. If the variable is 
const char *, there is no need to do the strdup.

> Couldn't we replace, for example :
>         r->method = apr_pstrdup(r->pool, "GET");
> by
>         r->method = "GET";

r->method is "const char *", so no need for the strdup in this case. 
Some other members of request_rec are not const, though. There may be 
some members which really should be const, but aren't, but I don't 
think we should change that in 2.x.

Mime
View raw message