From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18036 invoked by alias); 26 Mar 2012 18:56:30 -0000 Received: (qmail 18028 invoked by uid 22791); 26 Mar 2012 18:56:29 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 26 Mar 2012 18:56:14 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2QIu4w9010332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Mar 2012 14:56:13 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2QGwMIb007015 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 26 Mar 2012 12:58:23 -0400 From: Tom Tromey To: HATAYAMA Daisuke Cc: gdb-patches@sourceware.org Subject: Re: question: python gc doesn't collect buffer allocated by read_memory() References: <20120319.151647.104032080.d.hatayama@jp.fujitsu.com> <87iphzhtvd.fsf@fleche.redhat.com> <20120321.131547.347143263.d.hatayama@jp.fujitsu.com> Date: Mon, 26 Mar 2012 18:56:00 -0000 In-Reply-To: <20120321.131547.347143263.d.hatayama@jp.fujitsu.com> (HATAYAMA Daisuke's message of "Wed, 21 Mar 2012 13:15:47 +0900 ( )") Message-ID: <87iphrs3ip.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: 2012-03/txt/msg00879.txt.bz2 >>>>> ">" == HATAYAMA Daisuke 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]).