Fix minor memory leak in Gamepad

This commit is contained in:
Joshua Granick
2018-04-03 17:02:26 -07:00
parent ecba26e560
commit 25e8649c20
2 changed files with 22 additions and 4 deletions

View File

@@ -793,7 +793,18 @@ namespace lime {
value lime_gamepad_get_device_guid (int id) {
const char* guid = Gamepad::GetDeviceGUID (id);
return guid ? alloc_string (guid) : alloc_null ();
if (guid) {
value result = alloc_string (guid);
delete guid;
return result;
} else {
return alloc_null ();
}
}

View File

@@ -66,10 +66,17 @@ namespace lime {
const char* Gamepad::GetDeviceGUID (int id) {
char* guid = new char[64];
SDL_Joystick* joystick = SDL_GameControllerGetJoystick (gameControllers[id]);
SDL_JoystickGetGUIDString (SDL_JoystickGetGUID (joystick), guid, 64);
return guid;
if (joystick) {
char* guid = new char[64];
SDL_JoystickGetGUIDString (SDL_JoystickGetGUID (joystick), guid, 64);
return guid;
}
return 0;
}