I have a true memory leak originating in the following function.
// Convert a UTF-8-encoded byte string to a wstring.
std::wstring Utf8ToWideString(const std::string& utf8str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> conv;
return conv.from_bytes(utf8str);
}
I understand that locale-specific function may allocate some memory once per thread, and keep it for the lifetime of the thread or even the whole process (as apparently happens here). This is not my case; in fact, I have about 2GB of extra memory in the process, and most of these apparently leaked heap blocks come in one of 2 sizes, and contain (each respective to each size) one the day of week names (...:Mon:Monday:Thu:...
), and another some time formats. These are leaked apparently per call. The allocations, according to WPA (a tool tracking allocations, the Windows-land cousin of valgrind), occur from inside a call to CRT function std::setlocale
. Also, there is not a big churn of threads, and absolute majority if not all of the conversion calls come from the same pool of threads.
My main question is: Am I using std::wstring_convert
correctly?
A secondary question, if there is not an obvious bug or uncommon pattern in my code, is this something of a known issue? My compiler is MSVS 2015, and the issue occurs with both Update 2 and Update 3 versions.