From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13584 invoked by alias); 5 Oct 2010 23:47:10 -0000 Received: (qmail 13569 invoked by uid 22791); 5 Oct 2010 23:47:09 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-bw0-f41.google.com (HELO mail-bw0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Oct 2010 23:47:03 +0000 Received: by bwz10 with SMTP id 10so6932785bwz.0 for ; Tue, 05 Oct 2010 16:47:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.71.139 with SMTP id h11mr8758784bkj.135.1286322420254; Tue, 05 Oct 2010 16:47:00 -0700 (PDT) Received: by 10.204.80.100 with HTTP; Tue, 5 Oct 2010 16:47:00 -0700 (PDT) In-Reply-To: References: Date: Tue, 05 Oct 2010 23:47:00 -0000 Message-ID: Subject: Re: [patch] Memory leak fixes From: Ali Lakhia To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2010-10/txt/msg00065.txt.bz2 On Tue, Oct 5, 2010 at 3:47 PM, Tom Tromey wrote: > Ali> diff -ru gdb-7.1/gdb/dwarf2read.c gdb-7.1/gdb/dwarf2read.c > Ali> --- gdb-7.1/gdb/dwarf2read.c =A0 =A0 =A0 2010-09-14 16:59:40.0000000= 00 -0700 > Ali> +++ gdb-7.1/gdb/dwarf2read.c =A0 =A0 =A0 2010-06-15 14:53:54.0000000= 00 -0700 > Ali> @@ -5462,6 +5462,7 @@ > Ali> =A0 =A0set_descriptive_type (type, die, cu); > Ali> =A0 =A0do_cleanups (back_to); > > Ali> + =A0xfree (range_types); > > This one seems to be fixed in CVS. > There is a cleanup covering range_types. Are you referring to the call to make_cleanup() ? That gets called only if ndim =3D=3D 0 and I can't really figure out what it is supposed to do with the arg other than saving it in a cleanup struct and returning that struct. > Actually, I see this cleanup in 7.1 as well. > How did you find this leak? > > Maybe the logic around creating the cleanup is wrong. I found the leak using a static checker. It is known to have false positives! :-) > Ali> diff -ru gdb-7.1/gdb/printcmd.c gdb-7.1/gdb/printcmd.c > Ali> --- gdb-7.1/gdb/printcmd.c 2010-09-14 17:03:28.000000000 -0700 > Ali> +++ gdb-7.1/gdb/printcmd.c 2010-06-15 14:53:54.000000000 -0700 > Ali> @@ -608,6 +608,7 @@ > Ali> =A0 =A0 =A0fputs_filtered (">", stream); > > Ali> =A0 =A0do_cleanups (cleanup_chain); > Ali> + =A0xfree (filename); > Ali> =A0} > > This one is also covered by a cleanup. I don't see any cleanup calls. filename gets allocated by build_address_symbolic() and nothing is freeing it as far as I can tell. > Ali> diff -ru gdb-7.1/gdb/python/py-type.c gdb-7.1/gdb/python/py-type.c > Ali> --- gdb-7.1/gdb/python/py-type.c =A0 2010-09-14 17:03:28.000000000 -= 0700 > Ali> +++ gdb-7.1/gdb/python/py-type.c =A0 2010-06-14 14:04:28.000000000 -= 0700 > Ali> @@ -580,6 +580,7 @@ > > Ali> =A0 =A0 =A0 =A0type_print (type_object_to_type (self), "", stb, -1); > > Ali> + =A0 =A0 =A0xfree (thetype); > Ali> =A0 =A0 =A0 =A0thetype =3D ui_file_xstrdup (stb, &length); > Ali> =A0 =A0 =A0 =A0do_cleanups (old_chain); > > I didn't check this one, but if you want to insert a free before a call > to do_cleanups, usually that means you should create a cleanup at the > point of allocation. The allocation is happing at the very next line at: ui_file_xstrdup() and the variable is used after the loop (I'm assuming TRY_CATCH macro can loop). So, it was safer to free to memory before the leak happens rather than after allocation, -Ali