[llvm-bugs] [Bug 51659] New: memory leak in regex

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 28 12:50:56 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51659

            Bug ID: 51659
           Summary: memory leak in regex
           Product: libc++
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvmbugzilla at pauldreik.se
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

The following program leaks memory (using clang 11 on Debian Bullseye, Debian
clang version 11.0.1-2):

paul at 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 at machine:~/code/stdfuzz/build$ clang++-11  --stdlib=libc++ problem.cpp
-fsanitize=leak -g
paul at 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>
>::__push_loop(unsigned long, unsigned long, std::__1::__owns_one_state<char>*,
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>
>::__push_greedy_inf_repeat(unsigned long, std::__1::__owns_one_state<char>*,
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>
>::basic_regex(char const*, std::__1::regex_constants::syntax_option_type)
/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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210828/c3877bb8/attachment.html>


More information about the llvm-bugs mailing list