diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 3b74f43d9..84379ff44 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -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 (); + + } } diff --git a/project/src/backend/sdl/SDLGamepad.cpp b/project/src/backend/sdl/SDLGamepad.cpp index 52b4f59ea..e8bba04e0 100644 --- a/project/src/backend/sdl/SDLGamepad.cpp +++ b/project/src/backend/sdl/SDLGamepad.cpp @@ -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; }