Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: gdb-patches@sourceware.org
Subject: Re: question: python gc doesn't collect buffer allocated by read_memory()
Date: Mon, 26 Mar 2012 18:56:00 -0000	[thread overview]
Message-ID: <87iphrs3ip.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20120321.131547.347143263.d.hatayama@jp.fujitsu.com> (HATAYAMA	Daisuke's message of "Wed, 21 Mar 2012 13:15:47 +0900 ( )")

>>>>> ">" == HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> writes:

>> Sorry for missing. I first found this on gdb-7.2-48.el6.x86_64. I used
>> 7.4 in the presentation of the first mail.

Thanks.

>> On the other hand, it appears to me that buffer objects returned by
>> inferior.read_memory() is never collected by gc.collect().

I think I found the problem.

The issue is that PyBuffer_FromReadWriteObject acquires a reference to
the base object -- but the code in gdb assumed that it stole a reference.

Could you try the appended patch?
It works for me; if it works for you, I will put it in.
If you can't try it, I'll just assume it is ok and go ahead...

Tom

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 339a221..0f5a6a3 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -405,7 +405,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
   CORE_ADDR addr, length;
   void *buffer = NULL;
   membuf_object *membuf_obj;
-  PyObject *addr_obj, *length_obj;
+  PyObject *addr_obj, *length_obj, *result;
   struct cleanup *cleanups;
   volatile struct gdb_exception except;
   static char *keywords[] = { "address", "length", NULL };
@@ -457,8 +457,10 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
   membuf_obj->addr = addr;
   membuf_obj->length = length;
 
-  return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
-				       Py_END_OF_BUFFER);
+  result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
+					 Py_END_OF_BUFFER);
+  Py_DECREF (membuf_obj);
+  return result;
 }
 
 /* Implementation of gdb.write_memory (address, buffer [, length]).


  reply	other threads:[~2012-03-26 18:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-19  6:17 HATAYAMA Daisuke
2012-03-20 20:59 ` Tom Tromey
2012-03-21  4:16   ` HATAYAMA Daisuke
2012-03-26 18:56     ` Tom Tromey [this message]
2012-03-27  1:52       ` HATAYAMA Daisuke
2012-03-28 17:37         ` Tom Tromey
2012-03-29  0:49           ` HATAYAMA Daisuke

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=87iphrs3ip.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=d.hatayama@jp.fujitsu.com \
    --cc=gdb-patches@sourceware.org \
    /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