Miscellaneous memory alloc related fixes
[deliverable/binutils-gdb.git] / bfd / som.c
index d7d4d8f845f37938a7aa7519ae82738a4ac82992..bd685920ba76273085fbf7911f5cc26443731ce8 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -4659,7 +4659,7 @@ som_slurp_symbol_table (bfd *abfd)
   size_t symsize = sizeof (struct som_external_symbol_dictionary_record);
   char *stringtab;
   struct som_external_symbol_dictionary_record *buf = NULL, *bufp, *endbufp;
-  som_symbol_type *sym, *symbase;
+  som_symbol_type *sym, *symbase = NULL;
   size_t amt;
 
   /* Return saved value if it exists.  */
@@ -4675,15 +4675,6 @@ som_slurp_symbol_table (bfd *abfd)
 
   stringtab = obj_som_stringtab (abfd);
 
-  if (_bfd_mul_overflow (symbol_count, sizeof (som_symbol_type), &amt))
-    {
-      bfd_set_error (bfd_error_file_too_big);
-      goto error_return;
-    }
-  symbase = bfd_zmalloc (amt);
-  if (symbase == NULL)
-    goto error_return;
-
   /* Read in the external SOM representation.  */
   if (_bfd_mul_overflow (symbol_count, symsize, &amt))
     {
@@ -4698,6 +4689,15 @@ som_slurp_symbol_table (bfd *abfd)
   if (bfd_bread (buf, amt, abfd) != amt)
     goto error_return;
 
+  if (_bfd_mul_overflow (symbol_count, sizeof (som_symbol_type), &amt))
+    {
+      bfd_set_error (bfd_error_file_too_big);
+      goto error_return;
+    }
+  symbase = bfd_zmalloc (amt);
+  if (symbase == NULL)
+    goto error_return;
+
   /* Iterate over all the symbols and internalize them.  */
   endbufp = buf + symbol_count;
   for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
@@ -4837,6 +4837,8 @@ som_slurp_symbol_table (bfd *abfd)
   return (TRUE);
 
  error_return:
+  if (symbase != NULL)
+    free (symbase);
   if (buf != NULL)
     free (buf);
   return FALSE;
This page took 0.023669 seconds and 4 git commands to generate.