3657: Don't leak memory on Windows in logger r=heinrich5991 a=def-

Thanks to 拓真 on Discord for report

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Vlad <51330274+gerdoe-jr@users.noreply.github.com>
Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-02-28 23:36:52 +00:00 committed by GitHub
commit 9556b4f59a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -177,10 +177,16 @@ static void logger_stdout_sync(const char *line, void *user)
char u16[4] = {0};
if(codepoint < 0)
{
free(wide);
return;
}
if(str_utf16le_encode(u16, codepoint) != 2)
{
free(wide);
return;
}
mem_copy(&wide[wlen], u16, 2);
}
@ -188,6 +194,7 @@ static void logger_stdout_sync(const char *line, void *user)
console = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsoleW(console, wide, wlen, NULL, NULL);
WriteConsoleA(console, "\n", 1, NULL, NULL);
free(wide);
}
#endif