This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[patch] c-common.c: Fix memory leak.


Hi,

Attached is a patch to fix memory leak.

Consider the "if" statement shown in the patch.  If we are returning
cstr.txt, nobody will ever reference namep, which is allocated via
XVECNEW a few lines up.

The patch solves this problem by freeing namep with XDELETEVEC.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-12-10  Kazu Hirata  <kazu@cs.umass.edu>

	* c-common.c (fname_as_string): Free namep if we are returning
	cstr.text.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.593
diff -u -d -p -r1.593 c-common.c
--- c-common.c	9 Dec 2004 22:55:41 -0000	1.593
+++ c-common.c	10 Dec 2004 15:18:37 -0000
@@ -755,7 +755,10 @@ fname_as_string (int pretty_p)
       strname.len = len - 1;
 
       if (cpp_interpret_string (parse_in, &strname, 1, &cstr, false))
-	return (char *) cstr.text;
+	{
+	  XDELETEVEC (namep);
+	  return (char *) cstr.text;
+	}
     }
   else
     namep = xstrdup (name);


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