You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-dev@quetz.apache.org by "Graham Dumpleton (JIRA)" <ji...@apache.org> on 2006/07/31 12:03:13 UTC

[jira] Created: (MODPYTHON-181) Memory leak when using handlers in multiple phases at same time.

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

                 Key: MODPYTHON-181
                 URL: http://issues.apache.org/jira/browse/MODPYTHON-181
             Project: mod_python
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.8, 3.1.4, 3.3
            Reporter: Graham Dumpleton
         Assigned To: Graham Dumpleton


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


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (MODPYTHON-181) Memory leak when using handlers in multiple phases at same time.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MODPYTHON-181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Graham Dumpleton closed MODPYTHON-181.
--------------------------------------


> Memory leak when using handlers in multiple phases at same time.
> ----------------------------------------------------------------
>
>                 Key: MODPYTHON-181
>                 URL: https://issues.apache.org/jira/browse/MODPYTHON-181
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1.4, 3.3, 3.2.8
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
>             Fix For: 3.3
>
>
> 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);

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Work started: (MODPYTHON-181) Memory leak when using handlers in multiple phases at same time.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-181?page=all ]

Work on MODPYTHON-181 started by Graham Dumpleton.

> Memory leak when using handlers in multiple phases at same time.
> ----------------------------------------------------------------
>
>                 Key: MODPYTHON-181
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-181
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.8, 3.1.4, 3.3
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
>
> 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);

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MODPYTHON-181) Memory leak when using handlers in multiple phases at same time.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/MODPYTHON-181?page=comments#action_12425493 ] 
            
Graham Dumpleton commented on MODPYTHON-181:
--------------------------------------------

Note that you will not actually see this change in the trunk now as changes related to MODPYTHON-155 have eliminated it, with the same handler list object now being kept for the whole life of the request and simply reused.

> Memory leak when using handlers in multiple phases at same time.
> ----------------------------------------------------------------
>
>                 Key: MODPYTHON-181
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-181
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1.4, 3.3, 3.2.8
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
>             Fix For: 3.3
>
>
> 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);

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (MODPYTHON-181) Memory leak when using handlers in multiple phases at same time.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-181?page=all ]

Graham Dumpleton resolved MODPYTHON-181.
----------------------------------------

    Fix Version/s: 3.3
       Resolution: Fixed

> Memory leak when using handlers in multiple phases at same time.
> ----------------------------------------------------------------
>
>                 Key: MODPYTHON-181
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-181
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1.4, 3.3, 3.2.8
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
>             Fix For: 3.3
>
>
> 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);

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira