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

Michael Snyder
2011-03-03T21:20:36Z

[-- Attachment #1: Type: text/plain, Size: 49 bytes --]

We don't have a separate libiberty list, do we?

[-- Attachment #2: cplus-dem.txt --]
[-- Type: text/plain, Size: 1026 bytes --]

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

* libiberty/cplus-dem.c (ada_demangle): Stop memory leak.
Also fix a one line indent problem.

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);