Patchwork Fix memory leaks in incpath.c

login
register
mail settings
Submitter Jakub Jelinek
Date Feb. 26, 2013, 9:22 p.m.
Message ID <20130226212228.GD12913@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/223403/
State New
Headers show

Comments

Jakub Jelinek - Feb. 26, 2013, 9:22 p.m.
Hi!

Another file with memory leaks.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-02-26  Jakub Jelinek  <jakub@redhat.com>

	* incpath.c (add_standard_paths): Use reconcat instead of concat
	where appropriate and avoid leaking memory.


	Jakub
Joseph S. Myers - Feb. 26, 2013, 11:23 p.m.
On Tue, 26 Feb 2013, Jakub Jelinek wrote:

> Hi!
> 
> Another file with memory leaks.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2013-02-26  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* incpath.c (add_standard_paths): Use reconcat instead of concat
> 	where appropriate and avoid leaking memory.

OK.

Patch

--- gcc/incpath.c.jj	2013-01-11 09:02:35.000000000 +0100
+++ gcc/incpath.c	2013-02-26 15:11:23.676815551 +0100
@@ -149,12 +149,17 @@  add_standard_paths (const char *sysroot,
 		{
 		  char *str = concat (iprefix, p->fname + len, NULL);
 		  if (p->multilib == 1 && imultilib)
-		    str = concat (str, dir_separator_str, imultilib, NULL);
+		    str = reconcat (str, str, dir_separator_str,
+				    imultilib, NULL);
 		  else if (p->multilib == 2)
 		    {
 		      if (!imultiarch)
-			continue;
-		      str = concat (str, dir_separator_str, imultiarch, NULL);
+			{
+			  free (str);
+			  continue;
+			}
+		      str = reconcat (str, str, dir_separator_str,
+				      imultiarch, NULL);
 		    }
 		  add_path (str, SYSTEM, p->cxx_aware, false);
 		}
@@ -183,6 +188,7 @@  add_standard_paths (const char *sysroot,
 		   && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
 	    {
  	      static const char *relocated_prefix;
+	      char *ostr;
 	      /* If this path starts with the configure-time prefix,
 		 but the compiler has been relocated, replace it
 		 with the run-time prefix.  The run-time exec prefix
@@ -198,22 +204,27 @@  add_standard_paths (const char *sysroot,
 		    = make_relative_prefix (dummy,
 					    cpp_EXEC_PREFIX,
 					    cpp_PREFIX);
+		  free (dummy);
 		}
-	      str = concat (relocated_prefix,
-			    p->fname + cpp_PREFIX_len,
-			    NULL);
-	      str = update_path (str, p->component);
+	      ostr = concat (relocated_prefix,
+			     p->fname + cpp_PREFIX_len,
+			     NULL);
+	      str = update_path (ostr, p->component);
+	      free (ostr);
 	    }
 	  else
 	    str = update_path (p->fname, p->component);
 
 	  if (p->multilib == 1 && imultilib)
-	    str = concat (str, dir_separator_str, imultilib, NULL);
+	    str = reconcat (str, str, dir_separator_str, imultilib, NULL);
 	  else if (p->multilib == 2)
 	    {
 	      if (!imultiarch)
-		continue;
-	      str = concat (str, dir_separator_str, imultiarch, NULL);
+		{
+		  free (str);
+		  continue;
+		}
+	      str = reconcat (str, str, dir_separator_str, imultiarch, NULL);
 	    }
 
 	  add_path (str, SYSTEM, p->cxx_aware, false);