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:
parent
9d2ebbc982
commit
8cf79aaf72
1 changed files with 6 additions and 1 deletions
|
@ -141,7 +141,12 @@ void KeyPoll::Poll(void)
|
||||||
else if ( evt.key.keysym.sym == SDLK_v &&
|
else if ( evt.key.keysym.sym == SDLK_v &&
|
||||||
keymap[SDLK_LCTRL] )
|
keymap[SDLK_LCTRL] )
|
||||||
{
|
{
|
||||||
keybuffer += SDL_GetClipboardText();
|
char* text = SDL_GetClipboardText();
|
||||||
|
if (text != NULL)
|
||||||
|
{
|
||||||
|
keybuffer += text;
|
||||||
|
SDL_free(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue