1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Fix memory leak when pasting text

According to SDL documentation[1], the returned pointer needs to be
freed. A glance at the source code confirms that the function allocates,
and also Valgrind complains about it.

Also if it couldn't allocate, the game no longer segfaults (std::strings
do not check if the pointer is non-NULL for operator+=).

[1]: https://wiki.libsdl.org/SDL_GetClipboardText
This commit is contained in:
Misa 2021-03-30 23:23:29 -07:00 committed by Ethan Lee
parent 9d2ebbc982
commit 8cf79aaf72

View file

@ -141,7 +141,12 @@ void KeyPoll::Poll(void)
else if ( evt.key.keysym.sym == SDLK_v &&
keymap[SDLK_LCTRL] )
{
keybuffer += SDL_GetClipboardText();
char* text = SDL_GetClipboardText();
if (text != NULL)
{
keybuffer += text;
SDL_free(text);
}
}
}
break;