internal/glfw: fix memory leak (#3008)

This commit is contained in:
XXIV 2024-06-04 07:00:20 +03:00 committed by GitHub
parent 7ddc349ae6
commit 216a110761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,8 +19,9 @@ func _glfwPlatformCreateTls(tls *C._GLFWtls) C.GLFWbool {
panic("glfw: TLS must not be allocated") panic("glfw: TLS must not be allocated")
} }
if pthread_key_create(&tls.posix.key, 0) != 0 { if pthread_key_create(&tls.posix.key, 0) != 0 {
_glfwInputError(int32(PlatformError), errstr := C.CString("POSIX: Failed to create context TLS")
C.CString("POSIX: Failed to create context TLS")) defer C.free(unsafe.Pointer(errstr))
_glfwInputError(int32(PlatformError), errstr)
return False return False
} }
tls.posix.allocated = True tls.posix.allocated = True
@ -58,7 +59,9 @@ func _glfwPlatformCreateMutex(mutex *C._GLFWmutex) C.GLFWbool {
panic("glfw: mutex must not be allocated") panic("glfw: mutex must not be allocated")
} }
if pthread_mutex_init(&mutex.posix.handle, nil) != 0 { 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 return False
} }
mutex.posix.allocated = True mutex.posix.allocated = True