Fix memory leak in guiConfirmRegistration
authorHybridDog <ovvv@web.de>
Wed, 27 Jun 2018 16:09:45 +0000 (18:09 +0200)
committerSmallJoker <mk939@ymail.com>
Fri, 6 Jul 2018 09:13:18 +0000 (11:13 +0200)
src/gui/guiConfirmRegistration.cpp
src/util/string.cpp

index 92ca94d425c0c3863ce7fc695e24376be7662e9c..fea9f5cda1371e577dd9cf4c9d7508aee52f38a7 100644 (file)
@@ -99,9 +99,10 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize)
                snprintf(info_text_buf, sizeof(info_text_buf), info_text_template.c_str(),
                                address.c_str(), m_playername.c_str());
 
-               gui::IGUIEditBox *e = new gui::intlGUIEditBox(
-                               utf8_to_wide_c(info_text_buf), true, Environment, this,
-                               ID_message, rect2, false, true);
+               wchar_t *info_text_buf_wide = utf8_to_wide_c(info_text_buf);
+               gui::IGUIEditBox *e = new gui::intlGUIEditBox(info_text_buf_wide, true,
+                               Environment, this, ID_message, rect2, false, true);
+               delete[] info_text_buf_wide;
                e->drop();
                e->setMultiLine(true);
                e->setWordWrap(true);
index 25f5734201143226e449a40ca9dd72bc44dbd12f..388e8d293c0b5feb993b9c1cc86f93195505409f 100644 (file)
@@ -167,6 +167,8 @@ std::string wide_to_utf8(const std::wstring &input)
 
 #endif // _WIN32
 
+// You must free the returned string!
+// The returned string is allocated using new
 wchar_t *utf8_to_wide_c(const char *str)
 {
        std::wstring ret = utf8_to_wide(std::string(str));