This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix memory leak in create_ada_exception_catchpoint


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cc12f4a8f97791cf9729ff9341f7c0fbd9d6a79e

commit cc12f4a8f97791cf9729ff9341f7c0fbd9d6a79e
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Feb 13 05:42:18 2019 -0700

    Fix memory leak in create_ada_exception_catchpoint
    
    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<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    	    Tom Tromey  <tromey@adacore.com>
    
    	* ada-lang.c (ada_exception_sal): Change addr_string to a
    	std::string.
    	(create_ada_exception_catchpoint): Update.

Diff:
---
 gdb/ChangeLog  | 7 +++++++
 gdb/ada-lang.c | 8 ++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 11667ae..37f505d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,13 @@
 2019-02-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 	    Tom Tromey  <tromey@adacore.com>
 
+	* ada-lang.c (ada_exception_sal): Change addr_string to a
+	std::string.
+	(create_ada_exception_catchpoint): Update.
+
+2019-02-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+	    Tom Tromey  <tromey@adacore.com>
+
 	* breakpoint.c (~bp_location): Rename from bp_location_dtor.
 	(bp_location_ops): Remove.
 	(base_breakpoint_allocate_location): Update.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 602facb..c775b09 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<ada_catchpoint> 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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]