Issue Details (XML | Word | Printable)

Key: MODPYTHON-181
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Memory leak when using handlers in multiple phases at same time.

Created: 31/Jul/06 10:02 AM   Updated: 01/May/07 10:37 AM
Return to search
Component/s: core
Affects Version/s: 3.1.4, 3.3.x, 3.2.8
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 01/Aug/06 12:11 AM


 Description  « Hide
When using handlers against multiple phases, ie.,

# .htaccess

PythonFixupHandler handlers
AddHandler mod_python .py
PythonHandler handlers

# handlers.py

from mod_python import apache

def handler(req):
  req.content_type = 'text/plain'
  req.write('handler')
  return apache.OK

def fixuphandler(req):
  return apache.OK

mod_python will leak memory on each request, which Apache child process sizes blowing out quite quickly.

The problem code is in python_handler() in 'src/mod_python.c'. Specifically the code does:

    if (!hle) {
        /* create a handler list object from dynamically registered handlers */
        request_obj->hlo = (hlistobject *)MpHList_FromHLEntry(dynhle, 1);
    }
    else {
        /* create a handler list object */
        request_obj->hlo = (hlistobject *)MpHList_FromHLEntry(hle, 1);

        /* add dynamically registered handlers, if any */
        if (dynhle) {
            MpHList_Append(request_obj->hlo, dynhle);
        }
    }

Problem is that request_obj->hlo can already be set by a prior phase's handler and by simply assigning to request_obj->hlo you get a memory leak as it refers to an existing Python object and it isn't being decref'd.

Thus, before this 'if' statement, it would appear that the following should
be inserted.

    if (request_obj->hlo)
        Py_DECREF(request_obj->hlo);

or:

    Py_XDECREF(request_obj->hlo);


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #427382 Tue Aug 01 00:11:28 UTC 2006 grahamd (MODPYTHON-181) Fixed memory leak when mod_python handlers are defined
for more than one phase at the same time.
Files Changed
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Repository Revision Date User Message
ASF #428316 Thu Aug 03 10:54:37 UTC 2006 grahamd (MODPYTHON-155) Improve memory efficiency related to req.add_handler()
and construction of handler list objects.
(MODPYTHON-181) Fix problems with req.add_handler() introduced when memory
leaks were eliminated related to handler list object.
Files Changed
MODIFY /httpd/mod_python/trunk/src/hlistobject.c
MODIFY /httpd/mod_python/trunk/src/filterobject.c
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/hlistobject.h
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h