[PATCH 01/10] change gdb to refcount bfd everywhere

Tom Tromey tromey@redhat.com
Mon Jul 23 15:23:00 GMT 2012


>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> And solib-svr4.c enable_break <interp_name> IMO leaks tmp_bfd.

Thanks for catching this.
Here is the patch.

Tom

2012-07-23  Tom Tromey  <tromey@redhat.com>

	* solib-svr4.c (enable_break): Update.
	* bfd-target.h (target_bfd_reopen): Update documentation.

diff --git a/gdb/bfd-target.h b/gdb/bfd-target.h
index 71001c5..7f4e628 100644
--- a/gdb/bfd-target.h
+++ b/gdb/bfd-target.h
@@ -23,9 +23,9 @@
 struct bfd;
 struct target_ops;
 
-/* Given an existing BFD, re-open it as a "struct target_ops".  On
-   close, it will also close the corresponding BFD (which is like
-   freopen and fdopen).  */
+/* Given an existing BFD, re-open it as a "struct target_ops".  This
+   acquires a new reference to the BFD.  This reference will be
+   released when the target is closed.  */
 struct target_ops *target_bfd_reopen (struct bfd *bfd);
 
 #endif
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 307e483..b636b71 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1558,9 +1558,11 @@ enable_break (struct svr4_info *info, int from_tty)
 	goto bkpt_at_symbol;
 
       /* Now convert the TMP_BFD into a target.  That way target, as
-         well as BFD operations can be used.  Note that closing the
-         target will also close the underlying bfd.  */
+         well as BFD operations can be used.  */
       tmp_bfd_target = target_bfd_reopen (tmp_bfd);
+      /* target_bfd_reopen acquired its own reference, so we can
+         release ours now.  */
+      gdb_bfd_unref (tmp_bfd);
 
       /* On a running target, we can get the dynamic linker's base
          address from the shared library table.  */
@@ -1670,8 +1672,9 @@ enable_break (struct svr4_info *info, int from_tty)
 						       sym_addr,
 						       tmp_bfd_target);
 
-      /* We're done with both the temporary bfd and target.  Remember,
-         closing the target closes the underlying bfd.  */
+      /* We're done with both the temporary bfd and target.  Closing
+         the target closes the underlying bfd, because it holds the
+         only remaining reference.  */
       target_close (tmp_bfd_target, 0);
 
       if (sym_addr != 0)



More information about the Gdb-patches mailing list