[mod_python] A few questions about requestobject.c

IndrekJärve indrek at inversion.ee
Wed Jul 30 11:33:51 EST 2003


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 :)

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?

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. Could the result
variable initialization perhaps be moved a bit further down to

a) when checking if rbuff from previous reads has a '\n' in it (perhaps
check with strchr and then initialize if needed) and 
b) after reading data from request and before copying it to the result.

At both these places it should be more obvious how much memory needs to
be allocated.

If I managed to make no sense at all and got something mixed up, please
let me know. However, I feel that at least the first point could use
some attention, as it creates a problem when uploading big files through
mod_python enabled scripts.


More information about the Mod_python mailing list