From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51277 invoked by alias); 11 Feb 2019 05:37:42 -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 51261 invoked by uid 89); 11 Feb 2019 05:37:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:7668, H*RU:sk:mailsec, H*r:sk:mailsec, Hx-spam-relays-external:sk:mailsec X-HELO: mailsec104.isp.belgacom.be Received: from mailsec104.isp.belgacom.be (HELO mailsec104.isp.belgacom.be) (195.238.20.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Feb 2019 05:37:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1549863460; x=1581399460; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=vwtBG5Gs4OH9X0AkN6L7h19fiRpO+uNFPVgoOCedO9U=; b=i8TIqWc0zN7Hp9uV34geVcL86W/L5QrlDmlDXkA77RH19c+3HsCj0Lx2 j3cKRNJMY0jTHq9aCpq/lAgfTDhXeA==; Received: from unknown (HELO md.home) ([109.130.122.147]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 11 Feb 2019 06:37:37 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leaks in ada catch command Date: Mon, 11 Feb 2019 05:37:00 -0000 Message-Id: <20190211053728.7668-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg00116.txt.bz2 Valgrind reports leaks such as the below in various gdb.ada tests: ==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) ... ==14141== 114 bytes in 4 blocks are definitely lost in loss record 1,055 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 0x3B82B3: set_breakpoint_location_function(bp_location*, int) (breakpoint.c:7156) ==14141== by 0x3C112B: add_location_to_breakpoint(breakpoint*, symtab_and_line const*) (breakpoint.c:8609) ==14141== by 0x3C127A: init_raw_breakpoint(breakpoint*, gdbarch*, symtab_and_line, bptype, breakpoint_ops const*) (breakpoint.c:7187) ==14141== by 0x3C1B52: init_ada_exception_breakpoint(breakpoint*, gdbarch*, symtab_and_line, char const*, breakpoint_ops const*, int, int, int) (breakpoint.c:11262) ==14141== by 0x381C2E: 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:13255) ... Fix the first leak by xfree-ing the addr_string allocated by ada_exception_sal. Fix the second leak by calling the base bp_location dtor. Tested on debian/amd64, natively and under valgrind. gdb/ChangeLog 2019-02-10 Philippe Waroquiers * breakpoint.c (bp_location_dtor): Rename to base_bp_location_dtor, make non static, and update users. * breakpoint.h (base_bp_location_dtor): Declare. * ada-lang.c (ada_catchpoint_location_dtor): Call base_bp_location_ops.dtor. (create_ada_exception_catchpoint): Free addr_string. --- gdb/ada-lang.c | 9 +++++++-- gdb/breakpoint.c | 8 ++++---- gdb/breakpoint.h | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index a878d4d1af..04911f41a1 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12415,6 +12415,8 @@ ada_catchpoint_location_dtor (struct bp_location *bl) struct ada_catchpoint_location *al = (struct ada_catchpoint_location *) bl; al->excep_cond_expr.reset (); + + base_bp_location_ops.dtor (bl); } /* The vtable to be used in Ada catchpoint locations. */ @@ -13246,13 +13248,16 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, int disabled, int from_tty) { - const char *addr_string = NULL; + char *addr_string = NULL; const struct breakpoint_ops *ops = NULL; - struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string, &ops); + struct symtab_and_line sal = ada_exception_sal (ex_kind, + (const char **) &addr_string, + &ops); std::unique_ptr c (new ada_catchpoint ()); init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string, ops, tempflag, disabled, from_tty); + xfree (addr_string); c->excep_string = excep_string; create_excep_cond_exprs (c.get (), ex_kind); if (!cond_string.empty ()) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index bd05707d48..1562d4d1dc 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -12168,14 +12168,14 @@ say_where (struct breakpoint *b) /* Default bp_location_ops methods. */ static void -bp_location_dtor (struct bp_location *self) +base_bp_location_dtor (struct bp_location *self) { xfree (self->function_name); } -static const struct bp_location_ops bp_location_ops = +const struct bp_location_ops base_bp_location_ops = { - bp_location_dtor + base_bp_location_dtor }; /* Destructor for the breakpoint base class. */ @@ -12190,7 +12190,7 @@ breakpoint::~breakpoint () static struct bp_location * base_breakpoint_allocate_location (struct breakpoint *self) { - return new bp_location (&bp_location_ops, self); + return new bp_location (&base_bp_location_ops, self); } static void diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 8c8c66a815..76bc129001 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -312,6 +312,10 @@ struct bp_location_ops void (*dtor) (struct bp_location *self); }; +/* Default bp_location_ops methods. */ + +extern const struct bp_location_ops base_bp_location_ops; + class bp_location { public: -- 2.20.1