From d9e1c69f5bbdb8148c1af50d2b7b703b549ad1c5 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 10 May 2026 13:45:04 +0700 Subject: [PATCH] Fix EINVAL at pthread_key_delete --- src/header/pthread/tls.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/header/pthread/tls.rs b/src/header/pthread/tls.rs index 83f2826c46..e2bb9e62dd 100644 --- a/src/header/pthread/tls.rs +++ b/src/header/pthread/tls.rs @@ -82,11 +82,15 @@ pub unsafe extern "C" fn pthread_key_create( #[unsafe(no_mangle)] pub unsafe extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int { - if KEYS.lock().remove(&key).is_none() || VALUES.borrow_mut().remove(&key).is_none() { + if KEYS.lock().remove(&key).is_none() { // We don't have to return anything, but it's not less expensive to ignore it. return EINVAL; } + // POSIX recommends to return EINVAL if the value does not "refers" + // to this key, but we do not map VALUES back to KEYS + VALUES.borrow_mut().remove(&key); + 0 }