<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - leak in __cxa_demangle"
   href="https://llvm.org/bugs/show_bug.cgi?id=31030">31030</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>leak in __cxa_demangle
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kcc@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>on fresh trunk: feed these 8 bytes into __cxa_demangle to get a memory leak: 

00000000: 5f5a 355a 835a 8340                      _Z5Z.Z.@


full reproducer: 

#include <stddef.h>
extern "C" char *
__cxa_demangle(const char *mangled_name, char *buf, size_t *n, int *status);


int main() {
  unsigned char buf[] = {0x5f, 0x5a, 0x35, 0x5a, 0x83, 0x5a, 0x83, 0x40, 0};
  __cxa_demangle((char*)buf, 0, 0, 0);
}


cc llvm/projects/libcxxabi/src
clang++ -std=c++11 -g   cxa_demangle.cpp -I../include repro.cc -o repro 
-fsanitize=address 

==20050==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 6 byte(s) in 1 object(s) allocated from:
    #0 0x4c1fce in realloc 
    #1 0x4f0c33 in __cxa_demangle
llvm/projects/libcxxabi/src/cxa_demangle.cpp:5023:47

(found by libFuzzer, see also
<a href="https://bugs.chromium.org/p/chromium/issues/detail?id=606626">https://bugs.chromium.org/p/chromium/issues/detail?id=606626</a>)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>