From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118400 invoked by alias); 30 Jun 2015 02:28:14 -0000 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 Received: (qmail 118345 invoked by uid 89); 30 Jun 2015 02:28:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f54.google.com Received: from mail-qg0-f54.google.com (HELO mail-qg0-f54.google.com) (209.85.192.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 30 Jun 2015 02:28:10 +0000 Received: by qgem68 with SMTP id m68so23514438qge.0 for ; Mon, 29 Jun 2015 19:28:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Zo7GuNr+qqC9LyuobMBczUa8D8juvkk9iF1Hql6UR08=; b=kmpL7coHjGwkCQGU6oaEx4Jlc2tZUfjLXIPMlX9MD0hwm46JCI2XeW0Uwxzk/Hff1R i9GJfePwIB6kyQtvpMHgcN6UsNheitvZ60g9d7jxvMUCoKXaOOJEJAYM7/av9YzfiEfW 55Esq9SMyMZyhF4dTkmNCf75rI+PKVFHE9MpxCzHMH5XB/OZSFQZNqSWX4gNaoIGkw1t s0BhwQSuE/0yitvfvM0V5nIieRZqSL2Aka6vj4wST+ibtz7m10j0xr79Px8sB/TaVokb yiqJrw/KUIGQLzXVH/QbxiqFkaPfgS2i+LTlcyUDlmvdLXSPAfpYwC+o573H81q0S2U2 vSYw== X-Gm-Message-State: ALoCoQlFyXmzFhGNfw18wYQneCQcJFt7VRemeQfrui4ZYnUL9wShbI3lL3FaGezBS+iMFv2wyZ9c X-Received: by 10.140.130.193 with SMTP id 184mr24576462qhc.2.1435631287712; Mon, 29 Jun 2015 19:28:07 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id h3sm12487104qgh.22.2015.06.29.19.28.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jun 2015 19:28:06 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH 1/2] Use gdbarch obstack to allocate types in alloc_type_arch Date: Tue, 30 Jun 2015 02:28:00 -0000 Message-Id: <1435631281-31970-1-git-send-email-patrick@parcs.ath.cx> X-SW-Source: 2015-06/txt/msg00616.txt.bz2 For the command "gdb gdb" valgrind currently reports 100s of individual memory leaks, 500 of which originate solely out of the function alloc_type_arch. This function allocates a "struct type" associated with the given gdbarch using malloc but apparently the types allocated by this function are never freed. This patch fixes these leaks by making the function alloc_type_arch allocate these gdbarch-associated types on the gdbarch obstack instead of on the general heap. Since, from what I can tell, the types allocated by this function are all fundamental "wired-in" types, such types would not benefit from more granular memory management anyway. They would likely live as long as the gdbarch is alive so allocating them on the gdbarch obstack makes sense. With this patch, the number of individual vargrind warnings emitted for the command "gdb gdb" drops from ~800 to ~300. Tested on x86_64-unknown-linux-gnu. Does this fix make sense? It may not be ideal (more disciplined memory management may be?), but for the time being it helps reduce the noise coming from valgrind. Or maybe there is a good reason that these types are allocated on the heap... gdb/ChangeLog: * gdbtypes.c (alloc_type_arch): Allocate the type on the given gdbarch obstack instead of on the heap. Update commentary accordingly. --- gdb/gdbtypes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index ca86fbd..979ed6c 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -187,7 +187,7 @@ alloc_type (struct objfile *objfile) /* Allocate a new GDBARCH-associated type structure and fill it with some defaults. Space for the type structure is allocated - on the heap. */ + on the obstack associated with GDBARCH. */ struct type * alloc_type_arch (struct gdbarch *gdbarch) @@ -198,8 +198,8 @@ alloc_type_arch (struct gdbarch *gdbarch) /* Alloc the structure and start off with all fields zeroed. */ - type = XCNEW (struct type); - TYPE_MAIN_TYPE (type) = XCNEW (struct main_type); + type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type); + TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type); TYPE_OBJFILE_OWNED (type) = 0; TYPE_OWNER (type).gdbarch = gdbarch; -- 2.5.0.rc0.5.g91e10c5.dirty