-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang 14/15 libc++: std::vector memory leak in case of iterator exception #58392
Comments
CC: @philnik777 |
Did some more testing. The problem does not occur with clang 12.0.1 and 13.0.1 together with libc++, so it looks like a regression starting with clang 14. Here is a sample program that uses Boost.Regex in combination with ICU: #include <boost/regex/icu.hpp>
int main()
{
try
{
// clang 15 leaks 12 bytes of memory
boost::make_u32regex("^\xed\xa0\x80$"); // single lowest lead surrogate U+D800
}
catch (...) {
}
return EXIT_SUCCESS;
} It leaks 12 bytes when run. The given string is the UTF-8 encoding of a single lead surrogate which is illegal because it is only one half of a character. Internally |
@llvm/issue-subscribers-clang-codegen |
This is actually a libc++ bug. We removed the base class in LLVM14, which caused this bug. I'll look into how to fix the bug in a nice way. Unfortunately we don't have delegating constructors yet in C++03. @var-const do you have interest in adding that to C++03? You mentioned something in a patch. Pinging @ldionne for awareness. |
Any idea when a fix for this issue could be available? I assume there is no chance for a backport to clang 15? |
Sorry, I had something else to do and then forgot about it. I've got https://reviews.llvm.org/D138601 to fix the issue now. I hope we can get it into LLVM15, since it's a pretty serious issue. |
Fixes #58392 Reviewed By: ldionne, #libc Spies: alexfh, hans, joanahalili, dblaikie, libcxx-commits Differential Revision: https://reviews.llvm.org/D138601
Thank you for the fix and the backport to clang 15.0.7! Works like a charm. |
The program below shows this memory leak when executed in Valgrind:
The program defines an iterator that at some point throws an exception in
operator*()
. Such behavior is common e.g. for Unicode iterators (UTF-8 and UTF-16) if they encounter illegal byte sequences (e.g. missing parts of surrogate pairs or incorrect leading/continuation bytes). It can be triggered with Boost.Regex when combined with the ICU library.The iterator constructor of std::vector is used to actually trigger the memory leak.
Combinations where the leak occurs:
Combinations where no leak occurs:
This looks like a regression in recent versions of libc++.
The program to reproduce the issue:
The text was updated successfully, but these errors were encountered: