From 907d9743520fcef6123a9e65e27d21981676a256 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 14 Feb 2011 20:51:29 -0600 Subject: [PATCH] Add calls to pthread_attr_destroy(). This patch adds a couple of missing calls to pthread_attr_destroy(). There were a couple of instances where pthread_attr_init() was being used without a cooresponding call to pthread_attr_destroy(). This also localizes the pthread_attr_t to the function where it is needed instead of having it persist (the man page specifically states that destroying the attributes structure has no effect on threads created using the attributes). Signed-off-by: Russell Bryant Reviewed-by: Steven Dake --- exec/coroipcs.c | 15 ++++++++------- exec/timer.c | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/exec/coroipcs.c b/exec/coroipcs.c index 18972311..b64c5a95 100644 --- a/exec/coroipcs.c +++ b/exec/coroipcs.c @@ -142,7 +142,6 @@ struct conn_info { int fd; pthread_t thread; pid_t client_pid; - pthread_attr_t thread_attr; unsigned int service; enum conn_state state; int refcount; @@ -1571,7 +1570,6 @@ int coroipcs_handler_dispatch ( int res; char buf; - if (ipc_thread_exiting (conn_info)) { return conn_info_destroy (conn_info); } @@ -1588,6 +1586,8 @@ int coroipcs_handler_dispatch ( * Read the header and process it */ if (conn_info->service == SOCKET_SERVICE_INIT && (revent & POLLIN)) { + pthread_attr_t thread_attr; + /* * Receive in a nonblocking fashion the request * IF security invalid, send ERR_SECURITY, otherwise @@ -1684,21 +1684,22 @@ int coroipcs_handler_dispatch ( /* create stats objects */ coroipcs_init_conn_stats (conn_info); - pthread_attr_init (&conn_info->thread_attr); + pthread_attr_init (&thread_attr); /* * IA64 needs more stack space then other arches */ #if defined(__ia64__) - pthread_attr_setstacksize (&conn_info->thread_attr, 400000); + pthread_attr_setstacksize (&thread_attr, 400000); #else - pthread_attr_setstacksize (&conn_info->thread_attr, 200000); + pthread_attr_setstacksize (&thread_attr, 200000); #endif - pthread_attr_setdetachstate (&conn_info->thread_attr, PTHREAD_CREATE_JOINABLE); + pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_JOINABLE); res = pthread_create (&conn_info->thread, - &conn_info->thread_attr, + &thread_attr, pthread_ipc_consumer, conn_info); + pthread_attr_destroy (&thread_attr); /* * Security check - disallow multiple configurations of diff --git a/exec/timer.c b/exec/timer.c index 69f9a955..a89f4bcd 100644 --- a/exec/timer.c +++ b/exec/timer.c @@ -85,8 +85,6 @@ static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_t expiry_thread; -static pthread_attr_t thread_attr; - static struct timerlist timers_timerlist; static int sched_priority = 0; @@ -154,6 +152,7 @@ int corosync_timer_init ( int sched_priority_in) { int res; + pthread_attr_t thread_attr; timer_serialize_lock_fn = serialize_lock_fn; timer_serialize_unlock_fn = serialize_unlock_fn; @@ -169,6 +168,7 @@ int corosync_timer_init ( pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED); res = pthread_create (&expiry_thread, &thread_attr, prioritized_timer_thread, NULL); + pthread_attr_destroy (&thread_attr); return (res); } -- 2.39.5