From 216a110761116cebba4f5bbd4dae5a6c76200042 Mon Sep 17 00:00:00 2001 From: XXIV <13811862+thechampagne@users.noreply.github.com> Date: Tue, 4 Jun 2024 07:00:20 +0300 Subject: [PATCH] internal/glfw: fix memory leak (#3008) --- internal/glfw/posix_thread_darwin.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/glfw/posix_thread_darwin.go b/internal/glfw/posix_thread_darwin.go index 51b4deb5e..d3228e8e0 100644 --- a/internal/glfw/posix_thread_darwin.go +++ b/internal/glfw/posix_thread_darwin.go @@ -19,8 +19,9 @@ func _glfwPlatformCreateTls(tls *C._GLFWtls) C.GLFWbool { panic("glfw: TLS must not be allocated") } if pthread_key_create(&tls.posix.key, 0) != 0 { - _glfwInputError(int32(PlatformError), - C.CString("POSIX: Failed to create context TLS")) + errstr := C.CString("POSIX: Failed to create context TLS") + defer C.free(unsafe.Pointer(errstr)) + _glfwInputError(int32(PlatformError), errstr) return False } tls.posix.allocated = True @@ -58,7 +59,9 @@ func _glfwPlatformCreateMutex(mutex *C._GLFWmutex) C.GLFWbool { panic("glfw: mutex must not be allocated") } if pthread_mutex_init(&mutex.posix.handle, nil) != 0 { - _glfwInputError(int32(PlatformError), C.CString("POSIX: Failed to create mutex")) + errstr := C.CString("POSIX: Failed to create mutex") + defer C.free(unsafe.Pointer(errstr)) + _glfwInputError(int32(PlatformError), errstr) return False } mutex.posix.allocated = True