Fixed memory leak in cocoa _glfwPlatformGetKeyName

This commit is contained in:
Doug Binks 2013-08-14 18:35:32 +02:00
parent 9c68e11f2f
commit 363ec64321
2 changed files with 8 additions and 3 deletions

View File

@ -108,6 +108,7 @@ typedef struct _GLFWlibraryNS
GLboolean cursorHidden;
char* clipboardString;
char* keyName;
_GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryNS;

View File

@ -1098,7 +1098,11 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
const char* _glfwPlatformGetKeyName(int key)
{
// First try to translate virtual key mac os x style
// free temp keyname
free(_glfw.ns.keyName);
_glfw.ns.keyName = 0;
// Try to translate virtual key mac os x style
UInt16 vKey = 0;
switch(key)
{
@ -1189,8 +1193,8 @@ const char* _glfwPlatformGetKeyName(int key)
if (actualStringLength > 0 && status == noErr)
{
NSString* tempNS = [[NSString stringWithCharacters:unicodeString length:(NSUInteger)actualStringLength] uppercaseString];
char* pTodoFree = strdup([tempNS UTF8String]);
return pTodoFree;
_glfw.ns.keyName = strdup([tempNS UTF8String]);
return _glfw.ns.keyName;
}
}
}