Patchwork Go patch committed: Fix some space leaks

login
register
mail settings
Submitter Ian Taylor
Date Jan. 5, 2011, 5:33 a.m.
Message ID <mcrd3obnccv.fsf@google.com>
Download mbox | patch
Permalink /patch/77567/
State New
Headers show

Comments

Ian Taylor - Jan. 5, 2011, 5:33 a.m.
This patch to the Go frontend fixes a few space leaks.  This patch is
from Ettl Martin and is based on the results of the static code analysis
tool cppcheck (http://sourceforge.net/projects/cppcheck/).  This fixes
PRs 47158, 47159, 47160, and 47161.  Bootstrapped and ran Go testsuite
on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 7097e9178c67 go/expressions.cc
--- a/go/expressions.cc	Tue Jan 04 21:24:06 2011 -0800
+++ b/go/expressions.cc	Tue Jan 04 21:29:20 2011 -0800
@@ -8726,7 +8726,10 @@ 
 						       arg_val,
 						       location);
 	  if (args[i] == error_mark_node)
-	    return error_mark_node;
+	    {
+	      delete[] args;
+	      return error_mark_node;
+	    }
 	}
       gcc_assert(pp == params->end());
       gcc_assert(i == nargs);
@@ -8734,7 +8737,10 @@ 
 
   tree rettype = TREE_TYPE(TREE_TYPE(fntype->get_tree(gogo)));
   if (rettype == error_mark_node)
-    return error_mark_node;
+    {
+      delete[] args;
+      return error_mark_node;
+    }
 
   tree fn;
   if (has_closure)
@@ -8749,7 +8755,10 @@ 
     gcc_unreachable();
 
   if (fn == error_mark_node || TREE_TYPE(fn) == error_mark_node)
-    return error_mark_node;
+    {
+      delete[] args;
+      return error_mark_node;
+    }
 
   // This is to support builtin math functions when using 80387 math.
   tree fndecl = fn;
diff -r 7097e9178c67 go/gogo-tree.cc
--- a/go/gogo-tree.cc	Tue Jan 04 21:24:06 2011 -0800
+++ b/go/gogo-tree.cc	Tue Jan 04 21:29:20 2011 -0800
@@ -2832,7 +2832,11 @@ 
       types[i] = va_arg(ap, tree);
       args[i] = va_arg(ap, tree);
       if (types[i] == error_mark_node || args[i] == error_mark_node)
-	return error_mark_node;
+	{
+	  delete[] types;
+	  delete[] args;
+	  return error_mark_node;
+	}
     }
   va_end(ap);
 
diff -r 7097e9178c67 go/import-archive.cc
--- a/go/import-archive.cc	Tue Jan 04 21:24:06 2011 -0800
+++ b/go/import-archive.cc	Tue Jan 04 21:29:20 2011 -0800
@@ -180,16 +180,16 @@ 
     }
   if (filename == "/")
     {
-      char* buf = new char[size];
-      if (::read(this->fd_, buf, size) != size)
+      char* rdbuf = new char[size];
+      if (::read(this->fd_, rdbuf, size) != size)
 	{
 	  error_at(this->location_, "%s: could not read extended names",
 		   filename.c_str());
-	  delete buf;
+	  delete[] rdbuf;
 	  return false;
 	}
-      this->extended_names_.assign(buf, size);
-      delete buf;
+      this->extended_names_.assign(rdbuf, size);
+      delete[] rdbuf;
     }
 
   return true;
diff -r 7097e9178c67 go/import.cc
--- a/go/import.cc	Tue Jan 04 21:24:06 2011 -0800
+++ b/go/import.cc	Tue Jan 04 21:29:20 2011 -0800
@@ -244,11 +244,13 @@ 
   if (c < 0)
     {
       error_at(location, "read %s failed: %m", filename.c_str());
+      delete[] buf;
       return NULL;
     }
   if (c < sec_length)
     {
       error_at(location, "%s: short read", filename.c_str());
+      delete[] buf;
       return NULL;
     }