From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 384 invoked by alias); 6 Sep 2011 18:01:32 -0000 Received: (qmail 367 invoked by uid 22791); 6 Sep 2011 18:01:31 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,TW_RG,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from qmta11.westchester.pa.mail.comcast.net (HELO QMTA11.westchester.pa.mail.comcast.net) (76.96.59.211) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Sep 2011 18:01:07 +0000 Received: from omta04.westchester.pa.mail.comcast.net ([76.96.62.35]) by QMTA11.westchester.pa.mail.comcast.net with comcast id VVi31h0050ldTLk5BW17dS; Tue, 06 Sep 2011 18:01:07 +0000 Received: from [10.127.238.91] ([65.206.2.68]) by omta04.westchester.pa.mail.comcast.net with comcast id VW0y1h0091U2a2h3QW10vq; Tue, 06 Sep 2011 18:01:05 +0000 From: Paul Koning Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [Python] Patch to fix memory leak Date: Tue, 06 Sep 2011 19:36:00 -0000 Message-Id: <9E006B29-53D6-475E-9024-E1E9933A99C6@comcast.net> To: gdb-patches@sourceware.org Mime-Version: 1.0 (Apple Message framework v1084) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-09/txt/msg00092.txt.bz2 PyList_Append increments the reference count of the item being appended to = the list, and two of the places in the GDB Python code that use it don't ta= ke that into account. The result is a memory leak. The attached patch fix= es that. Tested by using a debug build of Python with reference counting enabled, an= d turning on dumping of final leftover objects. I don't have commit privs. paul ChangeLog: 2011-09-06 Paul Koning * python/py-cmd.c (gdbpy_string_to_argv): Decrement reference count of item appended to list. * python/py-type.c (typy_fields): Likewise. Index: python/py-cmd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-cmd.c,v retrieving revision 1.15 diff -u -r1.15 py-cmd.c --- python/py-cmd.c 5 Aug 2011 14:24:10 -0000 1.15 +++ python/py-cmd.c 6 Sep 2011 17:50:48 -0000 @@ -685,14 +685,12 @@ if (argp =3D=3D NULL || PyList_Append (py_argv, argp) < 0) { - if (argp !=3D NULL) - { - Py_DECREF (argp); - } + Py_XDECREF (argp); Py_DECREF (py_argv); freeargv (c_argv); return NULL; } + Py_DECREF (argp); } =20 freeargv (c_argv); Index: python/py-type.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/python/py-type.c,v retrieving revision 1.20 diff -u -r1.20 py-type.c --- python/py-type.c 18 Aug 2011 16:17:39 -0000 1.20 +++ python/py-type.c 6 Sep 2011 17:50:48 -0000 @@ -246,6 +246,7 @@ Py_DECREF (result); return NULL; } + Py_DECREF (dict); } =20 return result;