From c6b2191643f9ee216dc400a9604ea7f769589022 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 23 Apr 2021 10:02:08 +1000 Subject: [PATCH] pthread: Cleanups for attr init/destroy * Zero all fields of the attr structure when initializing * Can implement pthread_attr_destroy() by calling pthread_attr_init() --- components/pthread/pthread.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/pthread/pthread.c b/components/pthread/pthread.c index 02178f56e5..130c3d8f4f 100644 --- a/components/pthread/pthread.c +++ b/components/pthread/pthread.c @@ -728,6 +728,7 @@ int pthread_mutexattr_init(pthread_mutexattr_t *attr) if (!attr) { return EINVAL; } + memset(attr, 0, sizeof(*attr)); attr->type = PTHREAD_MUTEX_NORMAL; attr->is_initialized = 1; return 0; @@ -769,6 +770,7 @@ int pthread_attr_init(pthread_attr_t *attr) { if (attr) { /* Nothing to allocate. Set everything to default */ + memset(attr, 0, sizeof(*attr)); attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT; attr->detachstate = PTHREAD_CREATE_JOINABLE; return 0; @@ -778,13 +780,8 @@ int pthread_attr_init(pthread_attr_t *attr) int pthread_attr_destroy(pthread_attr_t *attr) { - if (attr) { - /* Nothing to deallocate. Reset everything to default */ - attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT; - attr->detachstate = PTHREAD_CREATE_JOINABLE; - return 0; - } - return EINVAL; + /* Nothing to deallocate. Reset everything to default */ + return pthread_attr_init(attr); } int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)