Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Koning <paulkoning@comcast.net>
To: pmuldoon@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: [Python] Patch to fix memory leak
Date: Wed, 07 Sep 2011 12:29:00 -0000	[thread overview]
Message-ID: <DD33626E-7CAA-4900-A562-1492D7CEFD62@comcast.net> (raw)
In-Reply-To: <m3bouw3doj.fsf@redhat.com>


On Sep 7, 2011, at 5:27 AM, Phil Muldoon wrote:

> Paul Koning <paulkoning@comcast.net> writes:
> 
>> 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.
> 
> 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.  

Apart from looking at the source, I find the most helpful statement is in the C API document, Introduction, Reference Count details, which says that when you pass an object as an argument the called function may "steal" the reference, or not -- and few functions steal the reference.  (For that matter, few functions return borrowed references.)  So the general rule is that passed objects are not stolen, and returned objects are new references.  Stolen 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.
> 
> 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 once approved.

	paul


  parent reply	other threads:[~2011-09-07 10:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-06 19:36 Paul Koning
2011-09-07  9:33 ` Phil Muldoon
2011-09-07 10:35   ` Jan Kratochvil
2011-09-07 12:29   ` Paul Koning [this message]
2011-09-08 12:29     ` Sergio Durigan Junior
2011-09-15 18:08 ` PING: " Paul Koning
2011-09-15 18:34   ` Jan Kratochvil
2011-09-15 20:39     ` Paul Koning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DD33626E-7CAA-4900-A562-1492D7CEFD62@comcast.net \
    --to=paulkoning@comcast.net \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox