apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <brian.p...@cnet.com>
Subject Re: Declaring large stack variables...
Date Sat, 08 Dec 2001 01:46:05 GMT
[dev@apr.apache.org added to the distribution list because one of
my proposed solutions is an APR enhancement]

Brad Nicholes wrote:

>   It appears that we are running into the same problem with Apache 2.0
>that we had with Apache 1.3.  The problem is recursive functions that
>declare large stack variables such as:
>static int read_type_map(apr_file_t **map, negotiation_state *neg,
>request_rec *rr)
>    request_rec *r = neg->r;
>    apr_file_t *map_ = NULL;
>    apr_status_t status;
>    char buffer[MAX_STRING_LEN];           <------------ resolves to

That's definitely bad.  I can think of three solutions, given that this
buffer is used to read a line at a time with apr_file_gets():

1. Use a smaller buffer size
2. Allocate the buffer from a pool (but that solution has its own problems,
   because allocating an 8KB block from a pool will often necessitate
   an additional malloc)
3. Create a variant of apr_file_gets() that allocates its own space
   from a pool supplied by the caller.  (It could use a power-of-two

I think I like the third option the best.  Anybody else have an
opinion on this?


View raw message