mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 09:28:15 +03: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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user