Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Aug 2014 12:25:07 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r269750 - head/lib/libproc
Message-ID:  <53e61323.201e.1f54ad21@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Sat Aug  9 12:25:06 2014
New Revision: 269750
URL: http://svnweb.freebsd.org/changeset/base/269750

Log:
  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

Modified:
  head/lib/libproc/proc_sym.c

Modified: head/lib/libproc/proc_sym.c
==============================================================================
--- head/lib/libproc/proc_sym.c	Sat Aug  9 09:13:10 2014	(r269749)
+++ head/lib/libproc/proc_sym.c	Sat Aug  9 12:25:06 2014	(r269750)
@@ -57,21 +57,15 @@ demangle(const char *symbol, char *buf, 
 {
 #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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53e61323.201e.1f54ad21>