This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

[RFA] stabs.c, fix multiple memory leaks.


OK?

2011-03-08  Michael Snyder  <msnyder@vmware.com>

	* 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.

Index: stabs.c
===================================================================
RCS file: /cvs/src/src/binutils/stabs.c,v
retrieving revision 1.32
diff -u -p -r1.32 stabs.c
--- stabs.c	9 Apr 2010 14:40:13 -0000	1.32
+++ stabs.c	8 Mar 2011 22:38:18 -0000
@@ -1980,6 +1980,9 @@ parse_stab_enum_type (void *dhandle, con
       if (**pp != ',')
 	{
 	  bad_stab (orig);
+	  free (name);
+	  free (names);
+	  free (values);
 	  return DEBUG_TYPE_NULL;
 	}
       ++*pp;
@@ -2036,7 +2039,10 @@ parse_stab_struct_type (void *dhandle, s
       || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
       || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
 				   &ownvptr))
-    return DEBUG_TYPE_NULL;
+    {
+      free (fields);
+      return DEBUG_TYPE_NULL;
+    }
 
   if (! statics
       && baseclasses == NULL
@@ -2240,7 +2246,10 @@ parse_stab_struct_fields (void *dhandle,
 	{
 	  ++*pp;
 	  if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
-	    return FALSE;
+	    {
+	      free (fields);
+	      return FALSE;
+	    }
 	  ++c;
 	  continue;
 	}
@@ -2254,6 +2263,7 @@ parse_stab_struct_fields (void *dhandle,
       if (p == NULL)
 	{
 	  bad_stab (orig);
+	  free (fields);
 	  return FALSE;
 	}
 
@@ -2415,7 +2425,10 @@ parse_stab_one_struct_field (void *dhand
   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 +2440,7 @@ parse_stab_one_struct_field (void *dhand
       if (p == NULL)
 	{
 	  bad_stab (orig);
+	  free (name);
 	  return FALSE;
 	}
 
@@ -2444,6 +2458,7 @@ parse_stab_one_struct_field (void *dhand
   if (**pp != ',')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2452,6 +2467,7 @@ parse_stab_one_struct_field (void *dhand
   if (**pp != ',')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2460,6 +2476,7 @@ parse_stab_one_struct_field (void *dhand
   if (**pp != ';')
     {
       bad_stab (orig);
+      free (name);
       return FALSE;
     }
   ++*pp;
@@ -2570,7 +2587,7 @@ parse_stab_members (void *dhandle, struc
 	{
 	  debug_type type;
 	  bfd_boolean stub;
-	  char *argtypes;
+	  char *argtypes = NULL;
 	  enum debug_visibility visibility;
 	  bfd_boolean constp, volatilep, staticp;
 	  bfd_vma voffset;
@@ -2589,10 +2606,18 @@ parse_stab_members (void *dhandle, struc
 	      type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
 				      (debug_type **) NULL);
 	      if (type == DEBUG_TYPE_NULL)
-		return FALSE;
+		{
+		  free (name);
+		  free (variants);
+		  free (argtypes);
+		  return FALSE;
+		}
 	      if (**pp != ':')
 		{
 		  bad_stab (orig);
+		  free (name);
+		  free (variants);
+		  free (argtypes);
 		  return FALSE;
 		}
 	    }
@@ -2602,6 +2627,9 @@ parse_stab_members (void *dhandle, struc
 	  if (p == NULL)
 	    {
 	      bad_stab (orig);
+	      free (name);
+	      free (variants);
+	      free (argtypes);
 	      return FALSE;
 	    }
 
@@ -2673,6 +2701,9 @@ parse_stab_members (void *dhandle, struc
 	      if (**pp != ';')
 		{
 		  bad_stab (orig);
+		  free (name);
+		  free (variants);
+		  free (argtypes);
 		  return FALSE;
 		}
 	      ++*pp;
@@ -2704,6 +2735,9 @@ parse_stab_members (void *dhandle, struc
 		      if (**pp != ';')
 			{
 			  bad_stab (orig);
+			  free (name);
+			  free (variants);
+			  free (argtypes);
 			  return FALSE;
 			}
 		      ++*pp;
@@ -2747,18 +2781,31 @@ parse_stab_members (void *dhandle, struc
 
 	      class_type = stab_find_type (dhandle, info, typenums);
 	      if (class_type == DEBUG_TYPE_NULL)
-		return FALSE;
+		{
+		  free (name);
+		  free (variants);
+		  free (argtypes);
+		  return FALSE;
+		}
 	      return_type = debug_get_return_type (dhandle, type);
 	      if (return_type == DEBUG_TYPE_NULL)
 		{
 		  bad_stab (orig);
+		  free (name);
+		  free (variants);
+		  free (argtypes);
 		  return FALSE;
 		}
 	      type = parse_stab_argtypes (dhandle, info, class_type, name,
 					  tagname, return_type, argtypes,
 					  constp, volatilep, &physname);
 	      if (type == DEBUG_TYPE_NULL)
-		return FALSE;
+		{
+		  free (name);
+		  free (variants);
+		  free (argtypes);
+		  return FALSE;
+		}
 	    }
 
 	  if (cvars + 1 >= allocvars)
@@ -2782,7 +2829,12 @@ parse_stab_members (void *dhandle, struc
 								constp,
 								volatilep);
 	  if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
-	    return FALSE;
+	    {
+	      free (name);
+	      free (variants);
+	      free (argtypes);
+	      return FALSE;
+	    }
 
 	  ++cvars;
 	}
@@ -4108,7 +4160,10 @@ stab_demangle_qualified (struct stab_dem
 
 		      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)
 			{

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