From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7077 invoked by alias); 7 Sep 2011 10:44:59 -0000 Received: (qmail 7069 invoked by uid 22791); 7 Sep 2011 10:44:58 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from qmta10.emeryville.ca.mail.comcast.net (HELO qmta10.emeryville.ca.mail.comcast.net) (76.96.30.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Sep 2011 10:44:40 +0000 Received: from omta12.emeryville.ca.mail.comcast.net ([76.96.30.44]) by qmta10.emeryville.ca.mail.comcast.net with comcast id Vmka1h0010x6nqcAAmkaHy; Wed, 07 Sep 2011 10:44:34 +0000 Received: from [192.168.10.125] ([75.68.58.5]) by omta12.emeryville.ca.mail.comcast.net with comcast id Vmka1h00C06m2QB8YmkaSt; Wed, 07 Sep 2011 10:44:35 +0000 Subject: Re: [Python] Patch to fix memory leak Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Paul Koning In-Reply-To: Date: Wed, 07 Sep 2011 12:29:00 -0000 Cc: gdb-patches@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <9E006B29-53D6-475E-9024-E1E9933A99C6@comcast.net> To: pmuldoon@redhat.com 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/msg00115.txt.bz2 On Sep 7, 2011, at 5:27 AM, Phil Muldoon wrote: > Paul Koning writes: >=20 >> 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 take that into account. The result is a memory >> leak. The attached patch fixes that. >=20 > For some reason the Python API manual is silent about PyList_Append > incrementing the reference count. But I did check, and you are correct, > the reference count is incremented when added to a list.=20=20 Apart from looking at the source, I find the most helpful statement is in t= he C API document, Introduction, Reference Count details, which says that w= hen you pass an object as an argument the called function may "steal" the r= eference, or not -- and few functions steal the reference. (For that matte= r, few functions return borrowed references.) So the general rule is that = passed objects are not stolen, and returned objects are new references. St= olen and borrowed references are mentioned explicitly in the documentation = of the function in question, and silence means not borrowed, not stolen. >> Tested by using a debug build of Python with reference counting >> enabled, and turning on dumping of final leftover objects. >=20 > This is fine, thanks for doing this. I cannot give you check-in > permission as I am not a maintainer. Please wait until one of the > maintainers signs-off before you go ahead. I don't have write privs so I'm relying on someone else to do the commit on= ce approved. paul