Thread: Patch to fix memory leak in fetch in Python interface.

Patch to fix memory leak in fetch in Python interface.

From
Stephen Robert Norris
Date:
This stops the interface from leaking the row tuples (and thus the
results of every fetch).

    Stephen

--- pgmodule.c    Wed Oct 17 17:07:05 2001
+++ pgmodule.c.orig    Thu Oct 18 08:39:52 2001
@@ -561,11 +561,11 @@
             }
             else
                 str = PyString_FromString(PQgetvalue(self->last_result,
self->current_row, j));
-            PyTuple_SET_ITEM(rowtuple, j, str);
+            Py_DECREF(str);
+            PyTuple_SET_ITEM(rowtuple, j, Py_None);
         }

         PyList_Append(reslist, rowtuple);
-        Py_DECREF(rowtuple);
         self->current_row++;
     }


Attachment

Re: Patch to fix memory leak in fetch in Python interface.

From
Stephen Robert Norris
Date:
On Thu, 2001-10-18 at 08:46, Stephen Robert Norris wrote:
> This stops the interface from leaking the row tuples (and thus the
> results of every fetch).
>
>     Stephen

Of course, I screwed up the patch. This one is actually correct, I
think:

--- /root/pgmodule.c    Thu Oct 18 08:47:02 2001
+++ pgmodule.c    Thu Oct 18 08:47:25 2001
@@ -566,6 +566,7 @@
         }

         PyList_Append(reslist, rowtuple);
+        Py_DECREF(rowtuple);
         self->current_row++;
     }


Attachment

Re: Patch to fix memory leak in fetch in Python interface.

From
Bruce Momjian
Date:
Your patch has been added to the PostgreSQL unapplied patches list at:

    http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------



Checking application/pgp-signature: FAILURE
-- Start of PGP signed section.
> This stops the interface from leaking the row tuples (and thus the
> results of every fetch).
>
>     Stephen
>
> --- pgmodule.c    Wed Oct 17 17:07:05 2001
> +++ pgmodule.c.orig    Thu Oct 18 08:39:52 2001
> @@ -561,11 +561,11 @@
>              }
>              else
>                  str = PyString_FromString(PQgetvalue(self->last_result,
> self->current_row, j));
> -            PyTuple_SET_ITEM(rowtuple, j, str);
> +            Py_DECREF(str);
> +            PyTuple_SET_ITEM(rowtuple, j, Py_None);
>          }
>
>          PyList_Append(reslist, rowtuple);
> -        Py_DECREF(rowtuple);
>          self->current_row++;
>      }
>
-- End of PGP section, PGP failed!

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Patch to fix memory leak in fetch in Python interface.

From
Bruce Momjian
Date:
Previous version removed.

Your patch has been added to the PostgreSQL unapplied patches list at:

    http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------



Checking application/pgp-signature: FAILURE
-- Start of PGP signed section.
> On Thu, 2001-10-18 at 08:46, Stephen Robert Norris wrote:
> > This stops the interface from leaking the row tuples (and thus the
> > results of every fetch).
> >
> >     Stephen
>
> Of course, I screwed up the patch. This one is actually correct, I
> think:
>
> --- /root/pgmodule.c    Thu Oct 18 08:47:02 2001
> +++ pgmodule.c    Thu Oct 18 08:47:25 2001
> @@ -566,6 +566,7 @@
>          }
>
>          PyList_Append(reslist, rowtuple);
> +        Py_DECREF(rowtuple);
>          self->current_row++;
>      }
>
-- End of PGP section, PGP failed!

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Patch to fix memory leak in fetch in Python interface.

From
Gerhard Häring
Date:
On Thu, Oct 18, 2001 at 08:56:47AM +1000, Stephen Robert Norris wrote:
> On Thu, 2001-10-18 at 08:46, Stephen Robert Norris wrote:
> > This stops the interface from leaking the row tuples (and thus the
> > results of every fetch).
> >
> >     Stephen
>
> Of course, I screwed up the patch. This one is actually correct, I
> think:
>
> [patch snipped]

Yes, that one is correct.

Gerhard
--
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

Re: Patch to fix memory leak in fetch in Python interface.

From
Bruce Momjian
Date:
Patch applied.  Thanks.

---------------------------------------------------------------------------



Checking application/pgp-signature: FAILURE
-- Start of PGP signed section.
> On Thu, 2001-10-18 at 08:46, Stephen Robert Norris wrote:
> > This stops the interface from leaking the row tuples (and thus the
> > results of every fetch).
> >
> >     Stephen
>
> Of course, I screwed up the patch. This one is actually correct, I
> think:
>
> --- /root/pgmodule.c    Thu Oct 18 08:47:02 2001
> +++ pgmodule.c    Thu Oct 18 08:47:25 2001
> @@ -566,6 +566,7 @@
>          }
>
>          PyList_Append(reslist, rowtuple);
> +        Py_DECREF(rowtuple);
>          self->current_row++;
>      }
>
-- End of PGP section, PGP failed!

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026