This is the mail archive of the gdb-patches@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]

[RFC] Dispose properly of registered gdbarch'es at exit.


  I am trying to get GDB to release all the allocated
memory.
  Currently one of the biggest remaining chunk is the
allocated gdbarch.

  The patch below is an attempt to get rid of that leak.


Comments most welcome,


Pierre Muller
GDB pascal language maintainer

PS: It might seem unimportant for GDB executable,
but having a library that has no leak is useful...


2012-12-11  Pierre Muller  <muller@sourceware.org>

        * gdbarch.sh (gdbarch_free_registered): New static function.
        (_initialize_gdbarch): Add final cleanup for registered
        gdbarch'es.

Index: src/gdb/gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.550
diff -u -p -r1.550 gdbarch.sh
--- src/gdb/gdbarch.sh  21 Nov 2012 00:29:54 -0000      1.550
+++ src/gdb/gdbarch.sh  11 Dec 2012 17:10:37 -0000
@@ -2072,6 +2072,32 @@ gdbarch_printable_names (void)
   return arches;
 }

+static void
+gdbarch_free_registered (void *arg)
+{
+  struct gdbarch_registration *curr = *(struct gdbarch_registration **)arg;
+  gdb_assert (curr == gdbarch_registry);
+
+  while (curr)
+    {
+      struct gdbarch_list *list = curr->arches;
+      while (list)
+       {
+         if (list->gdbarch)
+           {
+             /* There is a gdb_assert on this inside gdbarch_free.  */
+             list->gdbarch->initialized_p = 0;
+             gdbarch_free (list->gdbarch);
+           }
+         curr->arches = list->next;
+         xfree (list);
+         list = curr->arches;
+       }
+      gdbarch_registry = curr->next;
+      xfree (curr);
+      curr = gdbarch_registry;
+    }
+}

 void
 gdbarch_register (enum bfd_architecture bfd_architecture,
@@ -2301,6 +2327,7 @@ When non-zero, architecture debugging is
                             NULL,
                             show_gdbarch_debug,
                             &setdebuglist, &showdebuglist);
+  make_final_cleanup (gdbarch_free_registered, &gdbarch_registry);
 }
 EOF



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