https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81068
Bug ID: 81068 Summary: Sanitizer memory leak in codecvt_utf8 Product: gcc Version: 5.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: piotr.stachura at delphi dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- Simple string conversion application compiled with -fsanitize=undefined results in runtime_error and memory leak. Code: -- #include <iostream> #include <codecvt> #include <locale> int main() { const uint8_t input_data[] = { 0x22, 0x44, 0xC2, 0x80, 0xC5, 0x96, 0xCD, 0x8B }; std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter; std::u16string output_string = converter.from_bytes((const char*)&input_data[0], (const char*)&input_data[7]); return 0; } -- Compilation command: g++ -fsanitize=address -fsanitize=undefined -std=c++11 1.cpp -o 1 Run results: /usr/include/c++/5/bits/locale_conv.h:68:48: runtime error: member call on address 0x60300000efe0 which does not point to an object of type '__codecvt_abstract_base' 0x60300000efe0: note: object is of type 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' 01 00 80 21 20 3b b7 eb 54 56 00 00 00 00 00 00 be be be be ff ff 10 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' /usr/include/c++/5/bits/codecvt.h:220:36: runtime error: member call on address 0x60300000efe0 which does not point to an object of type '__codecvt_abstract_base' 0x60300000efe0: note: object is of type 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' 01 00 80 21 20 3b b7 eb 54 56 00 00 00 00 00 00 be be be be ff ff 10 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' /usr/include/c++/5/bits/codecvt.h:202:32: runtime error: member call on address 0x60300000efe0 which does not point to an object of type '__codecvt_abstract_base' 0x60300000efe0: note: object is of type 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' 01 00 80 21 20 3b b7 eb 54 56 00 00 00 00 00 00 be be be be ff ff 10 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'std::codecvt_utf8<char16_t, 1114111ul, (std::codecvt_mode)0>' ================================================================= ==7612==ERROR: LeakSanitizer: detected memory leaks Direct leak of 384 byte(s) in 6 object(s) allocated from: #0 0x7fe5ef1ac911 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98911) #1 0x7fe5eee1e093 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x92093) SUMMARY: AddressSanitizer: 384 byte(s) leaked in 6 allocation(s). Notes: - issue also visible on gcc 6.2.0 - without -fsanitize=undefined, no errors and no memory leak.