<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - memory leak in regex"
   href="https://bugs.llvm.org/show_bug.cgi?id=51659">51659</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>memory leak in regex
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvmbugzilla@pauldreik.se
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following program leaks memory (using clang 11 on Debian Bullseye, Debian
clang version 11.0.1-2):

paul@machine:~/code/stdfuzz/build$ cat problem.cpp 
#include <regex>
int
main()
{
  std::regex{ R"(\(\)*)",
              std::regex_constants::icase | std::regex_constants::nosubs |
                std::regex::optimize | std::regex::collate | std::regex::grep
};
}


paul@machine:~/code/stdfuzz/build$ clang++-11  --stdlib=libc++ problem.cpp
-fsanitize=leak -g
paul@simdjson:~/code/stdfuzz/build$ ./a.out 

=================================================================
==18364==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x4172e8 in operator new(unsigned long)
(/home/paul/code/stdfuzz/build/a.out+0x4172e8)
    #1 0x44cb02 in std::__1::basic_regex<char, std::__1::regex_traits<char>
<span class="quote">>::__push_loop(unsigned long, unsigned long, std::__1::__owns_one_state<char>*,</span >
unsigned long, unsigned long, bool)
/usr/lib/llvm-11/bin/../include/c++/v1/regex:4699:23
    #2 0x44c962 in std::__1::basic_regex<char, std::__1::regex_traits<char>
<span class="quote">>::__push_greedy_inf_repeat(unsigned long, std::__1::__owns_one_state<char>*,</span >
unsigned int, unsigned int)
/usr/lib/llvm-11/bin/../include/c++/v1/regex:2863:10
    #3 0x44ddbd in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse_RE_dupl_symbol<char const*>(char
const*, char const*, std::__1::__owns_one_state<char>*, unsigned int, unsigned
int) /usr/lib/llvm-11/bin/../include/c++/v1/regex:3578:13
    #4 0x44dc4b in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse_simple_RE<char const*>(char const*,
char const*) /usr/lib/llvm-11/bin/../include/c++/v1/regex:3259:23
    #5 0x44db1c in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse_RE_expression<char const*>(char const*,
char const*) /usr/lib/llvm-11/bin/../include/c++/v1/regex:3239:35
    #6 0x436aff in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse_basic_reg_exp<char const*>(char const*,
char const*) /usr/lib/llvm-11/bin/../include/c++/v1/regex:3133:23
    #7 0x436cdb in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse_grep<char const*>(char const*, char
const*) /usr/lib/llvm-11/bin/../include/c++/v1/regex:4617:9
    #8 0x4366fd in char const* std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__parse<char const*>(char const*, char const*)
/usr/lib/llvm-11/bin/../include/c++/v1/regex:3107:19
    #9 0x4363e1 in void std::__1::basic_regex<char,
std::__1::regex_traits<char> >::__init<char const*>(char const*, char const*)
/usr/lib/llvm-11/bin/../include/c++/v1/regex:3077:31
    #10 0x43617f in std::__1::basic_regex<char, std::__1::regex_traits<char>
<span class="quote">>::basic_regex(char const*, std::__1::regex_constants::syntax_option_type)</span >
/usr/lib/llvm-11/bin/../include/c++/v1/regex:2556:9
    #11 0x43609f in main /home/paul/code/stdfuzz/build/problem.cpp:3:1
    #12 0x7f808b6bdd09 in __libc_start_main csu/../csu/libc-start.c:308:16

SUMMARY: LeakSanitizer: 16 byte(s) leaked in 1 allocation(s).

It reproduces on compiler explorer with clang 12 as well, clang trunk does not
work at the moment there.</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>