Print this page
Rich's feedback

@@ -21,24 +21,22 @@
  */
 /*
  * Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright 2017 Jason King
+ * Copyright 2018 Jason King
  */
 
 #include <mdb/mdb_modapi.h>
 #include <mdb/mdb_demangle.h>
 #include <mdb/mdb_err.h>
 #include <mdb/mdb.h>
 
-#include <demangle.h>
 #include <strings.h>
 #include <unistd.h>
 #include <dlfcn.h>
 #include <link.h>
-#include <sysdemangle.h>
 
 static void *
 mdb_dem_alloc(size_t len)
 {
         return (mdb_alloc(len, UM_SLEEP));

@@ -206,12 +204,15 @@
                 prefix++;               /* the ` is part of the prefix */
                 prefixlen = prefix - name;
         }
 
         res = sysdemangle(name + prefixlen, dmp->dm_lang, &mdb_dem_demops);
-        if (res == NULL && errno != EINVAL)
+        if (res == NULL) {
+                if (errno != EINVAL)
                 mdb_warn("Error while demangling");
+                return (-1);
+        }
 
         reslen = (res != NULL) ? strlen(res) : 0;
         reslen += prefixlen;
         reslen += 1;
 

@@ -227,12 +228,15 @@
                 dmp->dm_len = reslen;
         }
 
         if (prefixlen > 0)
                 (void) strlcpy(dmp->dm_buf, name, prefixlen);
-        if (res != NULL)
+
+        if (res != NULL) {
                 (void) strlcat(dmp->dm_buf, res, dmp->dm_len);
+                mdb_dem_free(res, strlen(res) + 1);
+        }
 
         /*
          * Save the position of the demangled string for mdb_dem_filter()
          */
         dmp->dm_dem = dmp->dm_buf + prefixlen;