20000-05-18 H.J. Lu (hjl@gnu.org)
[binutils-gdb.git] / gdb / utils.c
index aa1fccd2853bd9040a7605742c0bf2c546318ed6..45fdb1dd47b8055dd5858fac1ee51e0ccade7802 100644 (file)
@@ -203,6 +203,18 @@ make_cleanup_freeargv (arg)
   return make_my_cleanup (&cleanup_chain, do_freeargv, arg);
 }
 
+static void
+do_bfd_close_cleanup (void *arg)
+{
+  bfd_close (arg);
+}
+
+struct cleanup *
+make_cleanup_bfd_close (bfd *abfd)
+{
+  return make_cleanup (do_bfd_close_cleanup, abfd);
+}
+
 static void
 do_ui_file_delete (void *arg)
 {
@@ -378,8 +390,13 @@ void
 free_current_contents (void *ptr)
 {
   void **location = ptr;
+  if (location == NULL)
+    internal_error ("free_current_contents: NULL pointer");
   if (*location != NULL)
-    free (*location);
+    {
+      free (*location);
+      *location = NULL;
+    }
 }
 
 /* Provide a known function that does nothing, to use as a base for