Util: Fix resource leak in UTF-8 handling code

This commit is contained in:
Jeffrey Pfau 2015-04-22 22:02:55 -07:00
parent 8aa9c4503a
commit 2594015853
2 changed files with 3 additions and 1 deletions

View File

@ -19,6 +19,7 @@ Bugfixes:
- Qt: Fix controllers sometimes not loading the right profile - Qt: Fix controllers sometimes not loading the right profile
- GBA: Fix hang when loading a savestate if sync to video is enabled - GBA: Fix hang when loading a savestate if sync to video is enabled
- Debugger: Fix use-after-free in breakpoint clearing code - Debugger: Fix use-after-free in breakpoint clearing code
- Util: Fix resource leak in UTF-8 handling code
Misc: Misc:
- Qt: Show multiplayer numbers in window title - Qt: Show multiplayer numbers in window title
- Qt: Solar sensor can have shortcuts set - Qt: Solar sensor can have shortcuts set

View File

@ -178,13 +178,14 @@ char* utf16to8(const uint16_t* utf16, size_t length) {
offset = utf8 + bytes; offset = utf8 + bytes;
} else if (utf8Length >= utf8TotalBytes) { } else if (utf8Length >= utf8TotalBytes) {
char* newUTF8 = realloc(utf8, utf8TotalBytes * 2); char* newUTF8 = realloc(utf8, utf8TotalBytes * 2);
offset = offset - utf8 + newUTF8;
if (newUTF8 != utf8) { if (newUTF8 != utf8) {
free(utf8); free(utf8);
} }
if (!newUTF8) { if (!newUTF8) {
return 0; return 0;
} }
offset = offset - utf8 + newUTF8; utf8 = newUTF8;
memcpy(offset, buffer, bytes); memcpy(offset, buffer, bytes);
offset += bytes; offset += bytes;
} }