[mod_python] A few questions about requestobject.c

Gregory (Grisha) Trubetskoy grisha at modpython.org
Wed Jul 30 09:05:53 EST 2003



On Wed, 30 Jul 2003, Indrek [ISO-8859-1] J?rve wrote:
>
> I've been messing around in requestobject.c for a few hours and started
> wondering about the way a few things work. Since I'm not sure whether
> they are design decisions, apache related stuff or just weird things, I
> thought I'd ask the list :)

It's been so long we lost track of which of the three they are :-) (BTW, a
better list for this sort of thing is python-dev at httpd.apache.org).

> 1. The use of apr_palloc
>
> Multipart POST forms are parsed in util.py/FieldStorage using req's
> req_readline function, which happily apr_palloc'ates enough memory to
> read the remaining request data into memory, but never seems to free it
> (nasty if the users have a habit of uploading 100+MB files, especially
> once multiplied with the number of apache processes). Since the pool
> used is attached to the apache request, I'm not sure I should freely
> apr_pool_clear() or apr_pool_destroy() it either.
>
> I managed to release memory by replacing apr_palloc with malloc and
> adding a few free()s where required, but is this the right approach?

Yes, this would definitely be a problem because that memory isn't freed
until the end of the request... We could either create a separate pool,
which then can be apr_pool_cleared(), or just use malloc like you have...
I'll see if I can take a look at it later today. If you have a patch you
could send in, that'd be nice.

>
> 2. The use of PyString_FromStringAndSize()
>
> Again in the req_readline() function, the result variable is initialized
> at the size of the full remaining request data.

This would be a problem with 100M files too... Another thing that occured
to me is that it could be better to rewrite the request read() functions
to use the buckets interface, this way none of this would be an issue.

Grisha


More information about the Mod_python mailing list