Fix bug reported and analyzed by Olivier Crete:
[deliverable/binutils-gdb.git] / gdb / utils.c
index 3552b8d45591245ada4376ac37327a8ff1a8b56b..10c40c710d35b90de285478f5b88e76ba12bf329 100644 (file)
@@ -51,6 +51,7 @@
 #include "charset.h"
 #include "annotate.h"
 #include "filenames.h"
+#include "symfile.h"
 
 #include "inferior.h"          /* for signed_pointer_to_address */
 
@@ -260,6 +261,19 @@ make_cleanup_ui_file_delete (struct ui_file *arg)
   return make_my_cleanup (&cleanup_chain, do_ui_file_delete, arg);
 }
 
+static void
+do_free_section_addr_info (void *arg)
+{
+  free_section_addr_info (arg);
+}
+
+struct cleanup *
+make_cleanup_free_section_addr_info (struct section_addr_info *addrs)
+{
+  return make_my_cleanup (&cleanup_chain, do_free_section_addr_info, addrs);
+}
+
+
 struct cleanup *
 make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
                 void *arg)
@@ -974,51 +988,14 @@ void
 request_quit (int signo)
 {
   quit_flag = 1;
-  /* Restore the signal handler.  Harmless with BSD-style signals, needed
-     for System V-style signals.  So just always do it, rather than worrying
-     about USG defines and stuff like that.  */
+  /* Restore the signal handler.  Harmless with BSD-style signals,
+     needed for System V-style signals.  */
   signal (signo, request_quit);
 
   if (immediate_quit)
     quit ();
 }
 \f
-/* Memory management stuff (malloc friends).  */
-
-static void *
-mmalloc (void *md, size_t size)
-{
-  return malloc (size);                /* NOTE: GDB's only call to malloc() */
-}
-
-static void *
-mrealloc (void *md, void *ptr, size_t size)
-{
-  if (ptr == 0)                        /* Guard against old realloc's */
-    return mmalloc (md, size);
-  else
-    return realloc (ptr, size);        /* NOTE: GDB's only call to ralloc() */
-}
-
-static void *
-mcalloc (void *md, size_t number, size_t size)
-{
-  return calloc (number, size);        /* NOTE: GDB's only call to calloc() */
-}
-
-static void
-mfree (void *md, void *ptr)
-{
-  free (ptr);                  /* NOTE: GDB's only call to free() */
-}
-
-/* This used to do something interesting with USE_MMALLOC.
- * It can be retired any time.  -- chastain 2004-01-19.  */
-void
-init_malloc (void *md)
-{
-}
-
 /* Called when a memory allocation fails, with the number of bytes of
    memory requested in SIZE. */
 
@@ -1037,53 +1014,6 @@ nomem (long size)
     }
 }
 
-void *
-xmrealloc (void *md, void *ptr, size_t size)
-{
-  void *val;
-
-  /* See libiberty/xmalloc.c.  This function need's to match that's
-     semantics.  It never returns NULL.  */
-  if (size == 0)
-    size = 1;
-
-  if (ptr != NULL)
-    val = mrealloc (md, ptr, size);
-  else
-    val = mmalloc (md, size);
-  if (val == NULL)
-    nomem (size);
-
-  return (val);
-}
-
-void *
-xmcalloc (void *md, size_t number, size_t size)
-{
-  void *mem;
-
-  /* See libiberty/xmalloc.c.  This function need's to match that's
-     semantics.  It never returns NULL.  */
-  if (number == 0 || size == 0)
-    {
-      number = 1;
-      size = 1;
-    }
-
-  mem = mcalloc (md, number, size);
-  if (mem == NULL)
-    nomem (number * size);
-
-  return mem;
-}
-
-void
-xmfree (void *md, void *ptr)
-{
-  if (ptr != NULL)
-    mfree (md, ptr);
-}
-
 /* The xmalloc() (libiberty.h) family of memory management routines.
 
    These are like the ISO-C malloc() family except that they implement
@@ -1113,19 +1043,48 @@ xmalloc (size_t size)
 PTR                            /* OK: PTR */
 xrealloc (PTR ptr, size_t size)        /* OK: PTR */
 {
-  return xmrealloc (NULL, ptr, size);
+  void *val;
+
+  /* See libiberty/xmalloc.c.  This function need's to match that's
+     semantics.  It never returns NULL.  */
+  if (size == 0)
+    size = 1;
+
+  if (ptr != NULL)
+    val = realloc (ptr, size); /* OK: realloc */
+  else
+    val = malloc (size);               /* OK: malloc */
+  if (val == NULL)
+    nomem (size);
+
+  return (val);
 }
 
 PTR                            /* OK: PTR */
 xcalloc (size_t number, size_t size)
 {
-  return xmcalloc (NULL, number, size);
+  void *mem;
+
+  /* See libiberty/xmalloc.c.  This function need's to match that's
+     semantics.  It never returns NULL.  */
+  if (number == 0 || size == 0)
+    {
+      number = 1;
+      size = 1;
+    }
+
+  mem = calloc (number, size);         /* OK: xcalloc */
+  if (mem == NULL)
+    nomem (number * size);
+
+  return mem;
 }
 
 void
 xfree (void *ptr)
 {
-  xmfree (NULL, ptr);
+  if (ptr != NULL)
+    free (ptr);                /* OK: free */
 }
 \f
 
This page took 0.026396 seconds and 4 git commands to generate.