From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25299 invoked by alias); 29 Mar 2012 00:49:25 -0000 Received: (qmail 25286 invoked by uid 22791); 29 Mar 2012 00:49:24 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from fgwmail6.fujitsu.co.jp (HELO fgwmail6.fujitsu.co.jp) (192.51.44.36) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Mar 2012 00:49:09 +0000 Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id D03EF3EE0BC for ; Thu, 29 Mar 2012 09:49:05 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id BA9D245DEB4 for ; Thu, 29 Mar 2012 09:49:05 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 57E6845DEA6 for ; Thu, 29 Mar 2012 09:49:05 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 4C108E38001 for ; Thu, 29 Mar 2012 09:49:05 +0900 (JST) Received: from ml14.s.css.fujitsu.com (ml14.s.css.fujitsu.com [10.240.81.134]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 04872E38003 for ; Thu, 29 Mar 2012 09:49:05 +0900 (JST) Received: from ml14.css.fujitsu.com (ml14 [127.0.0.1]) by ml14.s.css.fujitsu.com (Postfix) with ESMTP id B74079F75FC; Thu, 29 Mar 2012 09:49:04 +0900 (JST) Received: from localhost (unknown [10.124.102.140]) by ml14.s.css.fujitsu.com (Postfix) with ESMTP id 1B5869F75FB; Thu, 29 Mar 2012 09:49:04 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Received: from univ9680[10.124.102.140] by univ9680 (FujitsuOutboundMailChecker v1.3.1/9992[10.124.102.140]); Thu, 29 Mar 2012 09:49:02 +0900 (JST) Date: Thu, 29 Mar 2012 00:49:00 -0000 Message-Id: <20120329.094856.310071246.d.hatayama@jp.fujitsu.com> To: tromey@redhat.com Cc: gdb-patches@sourceware.org Subject: Re: question: python gc doesn't collect buffer allocated by read_memory() From: HATAYAMA Daisuke In-Reply-To: <871uoc1va3.fsf@fleche.redhat.com> References: <87iphrs3ip.fsf@fleche.redhat.com> <20120327.105206.71087856.d.hatayama@jp.fujitsu.com> <871uoc1va3.fsf@fleche.redhat.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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/msg00966.txt.bz2 From: Tom Tromey Subject: Re: question: python gc doesn't collect buffer allocated by read_memory() Date: Wed, 28 Mar 2012 11:37:40 -0600 >>>>>> ">" == HATAYAMA Daisuke writes: > >>> I suspect another objects allocated remain while not collected. > > Thanks, you are correct. > > I used valgrind --tool=massif to find the problem. > > TRY_CATCH clears the cleanup chain, so making a cleanup in a TRY_CATCH > and then trying to run or discard it outside the TRY_CATCH will not > work; instead it leaks the cleanup. > > I am checking in the appended patch. It fixes both leaks. Verified > with massif. > > Tom > > 2012-03-28 Tom Tromey > > * python/py-inferior.c (infpy_read_memory): Remove cleanups and > explicitly free 'buffer' on exit paths. Decref 'membuf_object' > before returning. > After applying this patch, I no longer see any memory leak. Again, thanks for your help, Tom. (gdb) shell cat ./testpro.py import gdb import gc i = gdb.inferiors()[0] buf = gdb.parse_and_eval('buf') count = 100000 while count >= 0: i.read_memory(buf.address, buf.type.sizeof) count -= 1 gc.collect() (gdb) shell ps aux | head -n 1 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND (gdb) shell ps aux | grep gdb | grep -v grep hat 28071 0.6 0.3 81964 12364 pts/0 S+ 09:41 0:00 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403 (gdb) source ./testpro.py (gdb) shell ps aux | grep gdb | grep -v grep hat 28071 2.3 0.3 81968 12500 pts/0 S+ 09:41 0:00 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403 (gdb) source ./testpro.py (gdb) shell ps aux | grep gdb | grep -v grep hat 28071 2.7 0.3 81968 12500 pts/0 S+ 09:41 0:01 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403 (gdb) source ./testpro.py sh(gdb) shell ps aux | grep gdb | grep -v grep hat 28071 2.9 0.3 81968 12500 pts/0 S+ 09:41 0:02 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403 Thanks. HATAYAMA, Daisuke