Fixed Win32 joystick name memory leak.
diff --git a/src/win32_init.c b/src/win32_init.c
index c665825..a77422a 100644
--- a/src/win32_init.c
+++ b/src/win32_init.c
@@ -192,6 +192,8 @@
_glfwInitTimer();
+ _glfwInitJoysticks();
+
return GL_TRUE;
}
@@ -212,7 +214,7 @@
_glfw.win32.classAtom = 0;
}
- // TODO: Remove keyboard hook
+ _glfwTerminateJoysticks();
freeLibraries();
diff --git a/src/win32_joystick.c b/src/win32_joystick.c
index 7059792..1259e82 100644
--- a/src/win32_joystick.c
+++ b/src/win32_joystick.c
@@ -72,6 +72,32 @@
//////////////////////////////////////////////////////////////////////////
+////// GLFW internal API //////
+//////////////////////////////////////////////////////////////////////////
+
+//========================================================================
+// Initialize joystick interface
+//========================================================================
+
+void _glfwInitJoysticks(void)
+{
+}
+
+
+//========================================================================
+// Close all opened joystick handles
+//========================================================================
+
+void _glfwTerminateJoysticks(void)
+{
+ int i;
+
+ for (i = 0; i < GLFW_JOYSTICK_LAST; i++)
+ free(_glfw.win32.joystick[i].name);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@@ -235,9 +261,9 @@
_glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS));
- free(_glfw.win32.joyNames[i]);
- _glfw.win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname);
+ free(_glfw.win32.joystick[i].name);
+ _glfw.win32.joystick[i].name = _glfwCreateUTF8FromWideString(jc.szPname);
- return _glfw.win32.joyNames[i];
+ return _glfw.win32.joystick[i].name;
}
diff --git a/src/win32_platform.h b/src/win32_platform.h
index ee33288..f1c72fa 100644
--- a/src/win32_platform.h
+++ b/src/win32_platform.h
@@ -189,7 +189,9 @@
} winmm;
#endif // _GLFW_NO_DLOAD_WINMM
- char* joyNames[GLFW_JOYSTICK_LAST + 1];
+ struct {
+ char* name;
+ } joystick[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryWin32;
@@ -215,6 +217,10 @@
// Time
void _glfwInitTimer(void);
+// Joystick input
+void _glfwInitJoysticks(void);
+void _glfwTerminateJoysticks(void);
+
// OpenGL support
int _glfwCreateContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,