Patchwork libiberty/cplus-dem.c, ada-demangle: plug memory leak.

login
register
mail settings
Submitter Michael Snyder
Date March 3, 2011, 9:20 p.m.
Message ID <4D70061C.10904@vmware.com>
Download mbox | patch
Permalink /patch/85343/
State New
Headers show

Comments

Michael Snyder - March 3, 2011, 9:20 p.m.
We don't have a separate libiberty list, do we?
2011-03-03  Michael Snyder  <msnyder@vmware.com>

	* libiberty/cplus-dem.c (ada_demangle): Stop memory leak.
	Also fix a one line indent problem.
Jakub Jelinek - March 3, 2011, 9:30 p.m.
On Thu, Mar 03, 2011 at 01:20:28PM -0800, Michael Snyder wrote:
> 2011-03-03  Michael Snyder  <msnyder@vmware.com>
> 
> 	* libiberty/cplus-dem.c (ada_demangle): Stop memory leak.
> 	Also fix a one line indent problem.

No libiberty/ in libiberty/ChangeLog.

> @@ -1129,10 +1129,11 @@ ada_demangle (const char *mangled, int o
>  
>   unknown:
>    len0 = strlen (mangled);
> +  xfree (demangled);
>    demangled = XNEWVEC (char, len0 + 3);

xfree isn't ever used in libiberty/*, use either free, or
XDELETE/XDELETEVEC.  In fact, it seems to be defined only in gdb,
making cplus-dem.c dependent on gdb is obviously a wrong thing.

	Jakub

Patch

Index: cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.52
diff -u -p -u -p -r1.52 cplus-dem.c
--- cplus-dem.c	3 Jan 2011 21:05:58 -0000	1.52
+++ cplus-dem.c	3 Mar 2011 21:13:49 -0000
@@ -883,7 +883,7 @@  ada_demangle (const char *mangled, int o
   int len0;
   const char* p;
   char *d;
-  char *demangled;
+  char *demangled = NULL;
   
   /* Discard leading _ada_, which is used for library level subprograms.  */
   if (strncmp (mangled, "_ada_", 5) == 0)
@@ -1129,10 +1129,11 @@  ada_demangle (const char *mangled, int o
 
  unknown:
   len0 = strlen (mangled);
+  xfree (demangled);
   demangled = XNEWVEC (char, len0 + 3);
 
   if (mangled[0] == '<')
-     strcpy (demangled, mangled);
+    strcpy (demangled, mangled);
   else
     sprintf (demangled, "<%s>", mangled);