From 96ec3cdd8ea16c2d2ce6b9832505b266ec1b2062 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 9 Aug 2014 12:25:06 +0000 Subject: [PATCH] In r268463, I misplaced a return in demangle(), causing the function to erroneously skip symbols that were not mangled at all. Fix this by moving the return into the preceding if block. While here, simplify the code by letting __cxa_demangle() allocate the needed space for the demangled symbol. This also fixes a memory leak, which would occur whenever __cxa_demangle() failed. Reported by: pgj MFC after: 3 days --- lib/libproc/proc_sym.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index 4d600436c67..e1776a4e8e7 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -57,21 +57,15 @@ demangle(const char *symbol, char *buf, size_t len) { #ifndef NO_CXA_DEMANGLE char *dembuf; - size_t demlen; if (symbol[0] == '_' && symbol[1] == 'Z' && symbol[2]) { - dembuf = malloc(len); - if (!dembuf) - goto fail; - demlen = len; - dembuf = __cxa_demangle(symbol, dembuf, &demlen, NULL); + dembuf = __cxa_demangle(symbol, NULL, NULL, NULL); if (!dembuf) goto fail; strlcpy(buf, dembuf, len); free(dembuf); + return; } - - return; fail: #endif /* NO_CXA_DEMANGLE */ strlcpy(buf, symbol, len);