Print this page
libconv

@@ -475,32 +475,36 @@
 /* demangle C++ names */
 static char *
 demangled_name(char *s)
 {
         static char     *buf = NULL;
+        size_t          buflen = 0;
         const char      *dn;
         size_t          len;
 
         dn = conv_demangle_name(s);
 
         /*
          * If not demangled, just return the symbol name
          */
-        if (strcmp(s, dn) == 0)
+        if (dn == s)
                 return (s);
 
-        /*
-         * Demangled. Format it
-         */
-        if (buf != NULL)
-                free(buf);
-
         len = strlen(dn) + strlen(s) + 4;
+
+        if (buflen < len) {
+                free(buf);
         if ((buf = malloc(len)) == NULL)
                 return (s);
+                buflen = len;
+        }
 
-        (void) snprintf(buf, len, "%s\t[%s]", dn, s);
+        /*
+         * Demangled. Format it
+         */
+        (void) snprintf(buf, buflen, "%s\t[%s]", dn, s);
+        free(dn);
         return (buf);
 }
 
 /*
  * Print the symbol table.  Input is an ELF file descriptor, a

@@ -524,11 +528,11 @@
 
         if (gelf_getclass(elf_file) == ELFCLASS64)
                 adj = 8;
 
         while (range > 0) {
-                char            *sym_name = (char *)0;
+                char            *sym_name = NULL;
                 int             type, bind;
                 int             specsec;
                 unsigned int    shndx;
 
                 (void) gelf_getsym(sym_data, index, &sym);