diff options
author | dim <dim@FreeBSD.org> | 2014-08-12 17:56:48 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-08-12 17:56:48 +0000 |
commit | 3cca469e525710732bb61207061a7dbf9280fd57 (patch) | |
tree | 8409f656a637d571aaf62ba35fdbb200bd73b617 /lib | |
parent | e822669a5518882bea2ec05c50ccd5ec72ae682a (diff) | |
download | FreeBSD-src-3cca469e525710732bb61207061a7dbf9280fd57.zip FreeBSD-src-3cca469e525710732bb61207061a7dbf9280fd57.tar.gz |
MFC r269750:
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
PR: base/191981
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libproc/proc_sym.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index 4be1126..f2514b9 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); |