You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by nl...@apache.org on 2006/07/09 12:05:31 UTC

svn commit: r420275 - in /httpd/mod_python/trunk/src: _apachemodule.c requestobject.c util.c

Author: nlehuen
Date: Sun Jul  9 03:05:30 2006
New Revision: 420275

URL: http://svn.apache.org/viewvc?rev=420275&view=rev
Log:
Fix for #MODPYTHON-172 and other memory leaks in req.readlines and cfgtree_walk.

Modified:
    httpd/mod_python/trunk/src/_apachemodule.c
    httpd/mod_python/trunk/src/requestobject.c
    httpd/mod_python/trunk/src/util.c

Modified: httpd/mod_python/trunk/src/_apachemodule.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/_apachemodule.c?rev=420275&r1=420274&r2=420275&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/_apachemodule.c (original)
+++ httpd/mod_python/trunk/src/_apachemodule.c Sun Jul  9 03:05:30 2006
@@ -315,8 +315,13 @@
             _PyString_Resize(&key, strlen(ckey));
             _PyString_Resize(&val, strlen(cval));
 
-            if (key && val)
-                PyList_Append(pairs, Py_BuildValue("(O,O)", key, val));
+            if (key && val) {
+                PyObject* listitem = Py_BuildValue("(O,O)", key, val);
+                if(listitem) {
+                    PyList_Append(pairs, listitem);
+                    Py_DECREF(listitem);
+                }
+            }
 
         }
         Py_XDECREF(pair);

Modified: httpd/mod_python/trunk/src/requestobject.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/requestobject.c?rev=420275&r1=420274&r2=420275&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/requestobject.c (original)
+++ httpd/mod_python/trunk/src/requestobject.c Sun Jul  9 03:05:30 2006
@@ -1139,6 +1139,7 @@
     PyObject *line, *rlargs;
     long sizehint = -1;
     long size = 0;
+    long linesize;
 
     if (! PyArg_ParseTuple(args, "|l", &sizehint)) 
         return NULL;
@@ -1151,13 +1152,15 @@
         return PyErr_NoMemory();
 
     line = req_readline(self, rlargs);
-    while (line && (PyString_Size(line)>0)) {
+    while (line && ((linesize=PyString_Size(line))>0)) {
         PyList_Append(result, line);
-        size += PyString_Size(line);
+        size += linesize;
         if ((sizehint != -1) && (size >= size))
             break;
+        Py_DECREF(line);
         line = req_readline(self, args);
     }
+    Py_XDECREF(line);
 
     if (!line)
         return NULL;

Modified: httpd/mod_python/trunk/src/util.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/util.c?rev=420275&r1=420274&r2=420275&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/util.c (original)
+++ httpd/mod_python/trunk/src/util.c Sun Jul  9 03:05:30 2006
@@ -399,6 +399,8 @@
 
         PyList_Append(list, t);
 
+        Py_DECREF(t);
+
         if (dir->first_child) {
 
             PyObject *child = cfgtree_walk(dir->first_child);
@@ -406,6 +408,8 @@
                 return PyErr_NoMemory();
 
             PyList_Append(list, child);
+            
+            Py_DECREF(child);
 
         }
 



Re: svn commit: r420275 - in /httpd/mod_python/trunk/src: _apachemodule.c requestobject.c util.c

Posted by Nicolas Lehuen <ni...@lehuen.com>.
Yeah, I forgot about the appendix C in the documentation. I'm going to
correct this ASAP.

I know about the sizehint problem, I'm currently working on it. I just
wanted to fix it in a different commit to make backporting more easy. Also,
I want to write a unit test for it. This should be done in a few hours,
since I'm still on a holiday schedule :).

Regards,
Nicolas

2006/7/9, Graham Dumpleton <gr...@dscpl.com.au>:
>
>
> On 09/07/2006, at 8:05 PM, nlehuen@apache.org wrote:
>
> > Modified: httpd/mod_python/trunk/src/requestobject.c
> > URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/
> > requestobject.c?rev=420275&r1=420274&r2=420275&view=diff
> > ======================================================================
> > ========
> > --- httpd/mod_python/trunk/src/requestobject.c (original)
> > +++ httpd/mod_python/trunk/src/requestobject.c Sun Jul  9 03:05:30
> > 2006
> > @@ -1139,6 +1139,7 @@
> >      PyObject *line, *rlargs;
> >      long sizehint = -1;
> >      long size = 0;
> > +    long linesize;
> >
> >      if (! PyArg_ParseTuple(args, "|l", &sizehint))
> >          return NULL;
> > @@ -1151,13 +1152,15 @@
> >          return PyErr_NoMemory();
> >
> >      line = req_readline(self, rlargs);
> > -    while (line && (PyString_Size(line)>0)) {
> > +    while (line && ((linesize=PyString_Size(line))>0)) {
> >          PyList_Append(result, line);
> > -        size += PyString_Size(line);
> > +        size += linesize;
> >          if ((sizehint != -1) && (size >= size))
> >              break;
> > +        Py_DECREF(line);
> >          line = req_readline(self, args);
> >      }
> > +    Py_XDECREF(line);
> >
> >      if (!line)
> >          return NULL;
>
> Did you forget to commit Doc/appendixc.tex bug fix list and version
> files increment changes?
>
> BTW, we still need to address:
>
>    http://issues.apache.org/jira/browse/MODPYTHON-179
>
> in that function. :-)
>
> Sorry for not helping much of late. Have got myself side tracked on
> my own software.
>
> Graham
>

Re: svn commit: r420275 - in /httpd/mod_python/trunk/src: _apachemodule.c requestobject.c util.c

Posted by Graham Dumpleton <gr...@dscpl.com.au>.
On 09/07/2006, at 8:05 PM, nlehuen@apache.org wrote:

> Modified: httpd/mod_python/trunk/src/requestobject.c
> URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/ 
> requestobject.c?rev=420275&r1=420274&r2=420275&view=diff
> ====================================================================== 
> ========
> --- httpd/mod_python/trunk/src/requestobject.c (original)
> +++ httpd/mod_python/trunk/src/requestobject.c Sun Jul  9 03:05:30  
> 2006
> @@ -1139,6 +1139,7 @@
>      PyObject *line, *rlargs;
>      long sizehint = -1;
>      long size = 0;
> +    long linesize;
>
>      if (! PyArg_ParseTuple(args, "|l", &sizehint))
>          return NULL;
> @@ -1151,13 +1152,15 @@
>          return PyErr_NoMemory();
>
>      line = req_readline(self, rlargs);
> -    while (line && (PyString_Size(line)>0)) {
> +    while (line && ((linesize=PyString_Size(line))>0)) {
>          PyList_Append(result, line);
> -        size += PyString_Size(line);
> +        size += linesize;
>          if ((sizehint != -1) && (size >= size))
>              break;
> +        Py_DECREF(line);
>          line = req_readline(self, args);
>      }
> +    Py_XDECREF(line);
>
>      if (!line)
>          return NULL;

Did you forget to commit Doc/appendixc.tex bug fix list and version
files increment changes?

BTW, we still need to address:

   http://issues.apache.org/jira/browse/MODPYTHON-179

in that function. :-)

Sorry for not helping much of late. Have got myself side tracked on
my own software.

Graham