Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-181

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.4, 3.3.x, 3.2.8
    • 3.3.1
    • core
    • None

    Description

      When using handlers against multiple phases, ie.,

      1. .htaccess

      PythonFixupHandler handlers
      AddHandler mod_python .py
      PythonHandler handlers

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

      Attachments

        Activity

          People

            grahamd Graham Phillip Dumpleton
            grahamd Graham Phillip Dumpleton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: