From patchwork Wed Feb 13 13:45:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31438 Received: (qmail 86184 invoked by alias); 13 Feb 2019 13:45:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 85953 invoked by uid 89); 13 Feb 2019 13:45:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Feb 2019 13:45:13 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D20D456102; Wed, 13 Feb 2019 08:45:11 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id svcxR+ixHGOh; Wed, 13 Feb 2019 08:45:11 -0500 (EST) Received: from murgatroyd.Home (75-166-72-210.hlrn.qwest.net [75.166.72.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 7F0D35607B; Wed, 13 Feb 2019 08:45:11 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Fix memory leak in create_ada_exception_catchpoint Date: Wed, 13 Feb 2019 06:45:05 -0700 Message-Id: <20190213134505.20005-3-tromey@adacore.com> In-Reply-To: <20190213134505.20005-1-tromey@adacore.com> References: <20190213134505.20005-1-tromey@adacore.com> MIME-Version: 1.0 Phillipe noticed that create_ada_exception_catchpoint was not freeing the "addr_string" memory: ==14141== 114 bytes in 4 blocks are definitely lost in loss record 1,054 of 3,424 ==14141== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309) ==14141== by 0x405107: xmalloc (common-utils.c:44) ==14141== by 0x7563F9: xstrdup (xstrdup.c:34) ==14141== by 0x381B21: ada_exception_sal (ada-lang.c:13217) ==14141== by 0x381B21: create_ada_exception_catchpoint(gdbarch*, ada_exception_catchpoint_kind, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, int, int, int) (ada-lang.c:13251) ==14141== by 0x3820A8: catch_ada_exception_command(char const*, int, cmd_list_element*) (ada-lang.c:13285) ==14141== by 0x3F4828: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892) This patch fixes the problem by changing ada_exception_sal to return a std::string via its out parameter. gdb/ChangeLog 2019-02-13 Philippe Waroquiers Tom Tromey * ada-lang.c (ada_exception_sal): Change addr_string to a std::string. (create_ada_exception_catchpoint): Update. --- gdb/ChangeLog | 7 +++++++ gdb/ada-lang.c | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 602facb35e7..c775b09b89e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13176,7 +13176,7 @@ ada_exception_catchpoint_cond_string (const char *excep_string, static struct symtab_and_line ada_exception_sal (enum ada_exception_catchpoint_kind ex, - const char **addr_string, const struct breakpoint_ops **ops) + std::string *addr_string, const struct breakpoint_ops **ops) { const char *sym_name; struct symbol *sym; @@ -13196,7 +13196,7 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, error (_("Unable to insert catchpoint. %s is not a function."), sym_name); /* Set ADDR_STRING. */ - *addr_string = xstrdup (sym_name); + *addr_string = sym_name; /* Set OPS. */ *ops = ada_exception_breakpoint_ops (ex); @@ -13228,12 +13228,12 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, int disabled, int from_tty) { - const char *addr_string = NULL; + std::string addr_string; const struct breakpoint_ops *ops = NULL; struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string, &ops); std::unique_ptr c (new ada_catchpoint ()); - init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string, + init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (), ops, tempflag, disabled, from_tty); c->excep_string = excep_string; create_excep_cond_exprs (c.get (), ex_kind);