Skip to content

Commit

Permalink
posix: pthread: ensure pthread_key_delete() removes correct key
Browse files Browse the repository at this point in the history
Previously, `pthread_key_delete()` was only ever deleting key 0
rather than the key corresponding to the provided argument.

Signed-off-by: Christopher Friedt <[email protected]>
  • Loading branch information
cfriedt committed Nov 24, 2023
1 parent e3f5c96 commit a89fa32
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/posix/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/posix/pthread.h>
#include <zephyr/posix/pthread_key.h>
#include <zephyr/sys/bitarray.h>
#include <zephyr/sys/__assert.h>

struct pthread_key_data {
sys_snode_t node;
Expand Down Expand Up @@ -120,6 +121,8 @@ int pthread_key_create(pthread_key_t *key,
*/
int pthread_key_delete(pthread_key_t key)
{
size_t bit;
__unused int ret;
pthread_key_obj *key_obj;
struct pthread_key_data *key_data;
sys_snode_t *node_l, *next_node_l;
Expand All @@ -145,7 +148,9 @@ int pthread_key_delete(pthread_key_t key)
k_free((void *)key_data);
}

(void)sys_bitarray_free(&posix_key_bitarray, 1, 0);
bit = posix_key_to_offset(key_obj);
ret = sys_bitarray_free(&posix_key_bitarray, 1, bit);
__ASSERT_NO_MSG(ret == 0);

k_spin_unlock(&pthread_key_lock, key_key);

Expand Down

0 comments on commit a89fa32

Please sign in to comment.