Просмотр исходного кода

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 <russell@russellbryant.net>
Reviewed-by: Steven Dake <sdake@redhat.com>
Russell Bryant 15 лет назад
Родитель
Сommit
b38293edbe
2 измененных файлов с 10 добавлено и 9 удалено
  1. 8 7
      exec/coroipcs.c
  2. 2 2
      exec/timer.c

+ 8 - 7
exec/coroipcs.c

@@ -142,7 +142,6 @@ struct conn_info {
 	int fd;
 	int fd;
 	pthread_t thread;
 	pthread_t thread;
 	pid_t client_pid;
 	pid_t client_pid;
-	pthread_attr_t thread_attr;
 	unsigned int service;
 	unsigned int service;
 	enum conn_state state;
 	enum conn_state state;
 	int refcount;
 	int refcount;
@@ -1571,7 +1570,6 @@ int coroipcs_handler_dispatch (
 	int res;
 	int res;
 	char buf;
 	char buf;
 
 
-
 	if (ipc_thread_exiting (conn_info)) {
 	if (ipc_thread_exiting (conn_info)) {
 		return conn_info_destroy (conn_info);
 		return conn_info_destroy (conn_info);
 	}
 	}
@@ -1588,6 +1586,8 @@ int coroipcs_handler_dispatch (
 	 * Read the header and process it
 	 * Read the header and process it
 	 */
 	 */
 	if (conn_info->service == SOCKET_SERVICE_INIT && (revent & POLLIN)) {
 	if (conn_info->service == SOCKET_SERVICE_INIT && (revent & POLLIN)) {
+		pthread_attr_t thread_attr;
+
 		/*
 		/*
 		 * Receive in a nonblocking fashion the request
 		 * Receive in a nonblocking fashion the request
 		 * IF security invalid, send ERR_SECURITY, otherwise
 		 * IF security invalid, send ERR_SECURITY, otherwise
@@ -1684,21 +1684,22 @@ int coroipcs_handler_dispatch (
 		/* create stats objects */
 		/* create stats objects */
 		coroipcs_init_conn_stats (conn_info);
 		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
 		* IA64 needs more stack space then other arches
 		*/
 		*/
 		#if defined(__ia64__)
 		#if defined(__ia64__)
-		pthread_attr_setstacksize (&conn_info->thread_attr, 400000);
+		pthread_attr_setstacksize (&thread_attr, 400000);
 		#else
 		#else
-		pthread_attr_setstacksize (&conn_info->thread_attr, 200000);
+		pthread_attr_setstacksize (&thread_attr, 200000);
 		#endif
 		#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,
 		res = pthread_create (&conn_info->thread,
-			&conn_info->thread_attr,
+			&thread_attr,
 			pthread_ipc_consumer,
 			pthread_ipc_consumer,
 			conn_info);
 			conn_info);
+		pthread_attr_destroy (&thread_attr);
 
 
 		/*
 		/*
 		 * Security check - disallow multiple configurations of
 		 * Security check - disallow multiple configurations of

+ 2 - 2
exec/timer.c

@@ -85,8 +85,6 @@ static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 
 static pthread_t expiry_thread;
 static pthread_t expiry_thread;
 
 
-static pthread_attr_t thread_attr;
-
 static struct timerlist timers_timerlist;
 static struct timerlist timers_timerlist;
 
 
 static int sched_priority = 0;
 static int sched_priority = 0;
@@ -154,6 +152,7 @@ int corosync_timer_init (
 	int sched_priority_in)
 	int sched_priority_in)
 {
 {
 	int res;
 	int res;
+	pthread_attr_t thread_attr;
 
 
 	timer_serialize_lock_fn = serialize_lock_fn;
 	timer_serialize_lock_fn = serialize_lock_fn;
 	timer_serialize_unlock_fn = serialize_unlock_fn;
 	timer_serialize_unlock_fn = serialize_unlock_fn;
@@ -169,6 +168,7 @@ int corosync_timer_init (
 	pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
 	pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
 	res = pthread_create (&expiry_thread, &thread_attr,
 	res = pthread_create (&expiry_thread, &thread_attr,
 		prioritized_timer_thread, NULL);
 		prioritized_timer_thread, NULL);
+	pthread_attr_destroy (&thread_attr);
 
 
 	return (res);
 	return (res);
 }
 }