* stabs.c (parse_stab_enum_type): Fix memory leaks.
authorNick Clifton <nickc@redhat.com>
Fri, 25 Mar 2011 17:46:07 +0000 (17:46 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 25 Mar 2011 17:46:07 +0000 (17:46 +0000)
(parse_stab_struct_type): Ditto.
(parse_stab_struct_fields): Ditto.
(parse_stab_one_struct_field): Ditto.
(parse_stab_members): Ditto.
(stab_demangle_qualified): Ditto.

binutils/ChangeLog
binutils/stabs.c

index 07cfa8a6f4698c9a618308a9586c9886eeea17aa..4ee9ea9e684850a244f48377c93e03564436df7d 100644 (file)
        (tg_class_static_member): Likewise.
        (tg_class_method_variant): Likewise.
        (tg_class_static_method_variant): Likewise.
+       * stabs.c (parse_stab_enum_type): Fix memory leaks.
+       (parse_stab_struct_type): Ditto.
+       (parse_stab_struct_fields): Ditto.
+       (parse_stab_one_struct_field): Ditto.
+       (parse_stab_members): Ditto.
+       (stab_demangle_qualified): Ditto.
 
 2011-03-25  Pierre Muller  <muller@ics.u-strasbg.fr>
 
index f8fb48c678d6bc380e1604ac4aa48d0fdd139906..9534d6616acac2e8be7ab78fb2e2faa42bccfecd 100644 (file)
@@ -1,6 +1,6 @@
 /* stabs.c -- Parse stabs debugging information
    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+   2005, 2006, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
@@ -1980,6 +1980,9 @@ parse_stab_enum_type (void *dhandle, const char **pp)
       if (**pp != ',')
        {
          bad_stab (orig);
+         free (name);
+         free (names);
+         free (values);
          return DEBUG_TYPE_NULL;
        }
       ++*pp;
@@ -2021,7 +2024,7 @@ parse_stab_struct_type (void *dhandle, struct stab_handle *info,
 {
   bfd_vma size;
   debug_baseclass *baseclasses;
-  debug_field *fields;
+  debug_field *fields = NULL;
   bfd_boolean statics;
   debug_method *methods;
   debug_type vptrbase;
@@ -2036,7 +2039,11 @@ parse_stab_struct_type (void *dhandle, struct stab_handle *info,
       || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
       || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
                                   &ownvptr))
-    return DEBUG_TYPE_NULL;
+    {
+      if (fields != NULL)
+       free (fields);
+      return DEBUG_TYPE_NULL;
+    }
 
   if (! statics
       && baseclasses == NULL
@@ -2240,7 +2247,10 @@ parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
        {
          ++*pp;
          if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
-           return FALSE;
+           {
+             free (fields);
+             return FALSE;
+           }
          ++c;
          continue;
        }
@@ -2254,6 +2264,7 @@ parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
       if (p == NULL)
        {
          bad_stab (orig);
+         free (fields);
          return FALSE;
        }
 
@@ -2415,7 +2426,10 @@ parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
   type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
                          (debug_type **) NULL);
   if (type == DEBUG_TYPE_NULL)
-    return FALSE;
+    {
+      free (name);
+      return FALSE;
+    }
 
   if (**pp == ':')
     {
@@ -2427,6 +2441,7 @@ parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
       if (p == NULL)
        {
          bad_stab (orig);
+         free (name);
          return FALSE;
        }
 
@@ -2444,6 +2459,7 @@ parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
   if (**pp != ',')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2452,6 +2468,7 @@ parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
   if (**pp != ',')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2460,6 +2477,7 @@ parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
   if (**pp != ';')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2511,6 +2529,9 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
   debug_method *methods;
   unsigned int c;
   unsigned int alloc;
+  char *name = NULL;
+  debug_method_variant *variants = NULL;
+  char *argtypes = NULL;
 
   *retp = NULL;
 
@@ -2523,8 +2544,6 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
   while (**pp != ';')
     {
       const char *p;
-      char *name;
-      debug_method_variant *variants;
       unsigned int cvars;
       unsigned int allocvars;
       debug_type look_ahead_type;
@@ -2553,7 +2572,7 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
          if (*p != '.')
            {
              bad_stab (orig);
-             return FALSE;
+             goto fail;
            }
          name = savestring (*pp, p - *pp);
          *pp = p + 1;
@@ -2570,7 +2589,6 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
        {
          debug_type type;
          bfd_boolean stub;
-         char *argtypes;
          enum debug_visibility visibility;
          bfd_boolean constp, volatilep, staticp;
          bfd_vma voffset;
@@ -2589,11 +2607,12 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
              type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
                                      (debug_type **) NULL);
              if (type == DEBUG_TYPE_NULL)
-               return FALSE;
+               goto fail;
+
              if (**pp != ':')
                {
                  bad_stab (orig);
-                 return FALSE;
+                 goto fail;
                }
            }
 
@@ -2602,7 +2621,7 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
          if (p == NULL)
            {
              bad_stab (orig);
-             return FALSE;
+             goto fail;
            }
 
          stub = FALSE;
@@ -2673,7 +2692,7 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
              if (**pp != ';')
                {
                  bad_stab (orig);
-                 return FALSE;
+                 goto fail;
                }
              ++*pp;
              voffset &= 0x7fffffff;
@@ -2704,7 +2723,7 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
                      if (**pp != ';')
                        {
                          bad_stab (orig);
-                         return FALSE;
+                         goto fail;
                        }
                      ++*pp;
                    }
@@ -2747,18 +2766,18 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
 
              class_type = stab_find_type (dhandle, info, typenums);
              if (class_type == DEBUG_TYPE_NULL)
-               return FALSE;
+               goto fail;
              return_type = debug_get_return_type (dhandle, type);
              if (return_type == DEBUG_TYPE_NULL)
                {
                  bad_stab (orig);
-                 return FALSE;
+                 goto fail;
                }
              type = parse_stab_argtypes (dhandle, info, class_type, name,
                                          tagname, return_type, argtypes,
                                          constp, volatilep, &physname);
              if (type == DEBUG_TYPE_NULL)
-               return FALSE;
+               goto fail;
            }
 
          if (cvars + 1 >= allocvars)
@@ -2782,7 +2801,7 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
                                                                constp,
                                                                volatilep);
          if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
-           return FALSE;
+           goto fail;
 
          ++cvars;
        }
@@ -2811,6 +2830,15 @@ parse_stab_members (void *dhandle, struct stab_handle *info,
   *retp = methods;
 
   return TRUE;
+
+ fail:
+  if (name != NULL)
+    free (name);
+  if (variants != NULL)
+    free (variants);
+  if (argtypes != NULL)
+    free (argtypes);
+  return FALSE;
 }
 
 /* Parse a string representing argument types for a method.  Stabs
@@ -4108,7 +4136,10 @@ stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
 
                      ft = debug_get_field_type (minfo->dhandle, *fields);
                      if (ft == NULL)
-                       return FALSE;
+                       {
+                         free (name);
+                         return FALSE;
+                       }
                      dn = debug_get_type_name (minfo->dhandle, ft);
                      if (dn != NULL && strcmp (dn, name) == 0)
                        {
This page took 0.031424 seconds and 4 git commands to generate.