You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Christophe JAILLET <ch...@wanadoo.fr> on 2011/06/28 22:03:10 UTC

Why 'apr_pstrdup' constant strings ?

Hi,

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 ?

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

CJ




Re: Why 'apr_pstrdup' constant strings ?

Posted by Stefan Fritsch <sf...@sfritsch.de>.
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.