cluster: STABLE3 - rgmanager: Clean up thread handling

Lon Hohberger lon@fedoraproject.org
Thu Mar 19 16:20:00 GMT 2009


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=fb37e5ab6be596f09bef22cdf28f68e4154c1d82
Commit:        fb37e5ab6be596f09bef22cdf28f68e4154c1d82
Parent:        7644f3bb56f130fe8546fb70fb8bbb12bd56c325
Author:        Lon Hohberger <lhh@redhat.com>
AuthorDate:    Thu Mar 19 12:19:08 2009 -0400
Committer:     Lon Hohberger <lhh@redhat.com>
CommitterDate: Thu Mar 19 12:19:08 2009 -0400

rgmanager: Clean up thread handling

* free memory if we fail to malloc our args
* Don't use C++ reserved word 'new' for a variable

Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
 rgmanager/src/clulib/tmgr.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/rgmanager/src/clulib/tmgr.c b/rgmanager/src/clulib/tmgr.c
index f2cb2db..a86d258 100644
--- a/rgmanager/src/clulib/tmgr.c
+++ b/rgmanager/src/clulib/tmgr.c
@@ -76,32 +76,37 @@ __wrap_pthread_create(pthread_t *th, const pthread_attr_t *attr,
 	 	      void *arg)
 {
 	void *fn = start_routine;
-	mthread_t *new;
+	mthread_t *newthread;
 	thread_arg_t *targ;
 	int ret;
 
-	new = malloc(sizeof (*new));
+	newthread = malloc(sizeof (*newthread));
+	if (!newthread)
+		return -1;
 	targ = malloc(sizeof (*targ));
-	if (!targ||!new)
+	if (!targ) {
+		free(newthread)
 		return -1;
+	}
+
 	targ->real_thread_fn = start_routine;
 	targ->real_thread_arg = arg;
 
 	ret = __real_pthread_create(th, attr, setup_thread, targ);
 	if (ret) {
-		if (new)
-			free(new);
+		if (newthread)
+			free(newthread);
 		if (targ)
 			free(targ);
 		return ret;
 	}
 
-	if (new) {
-		new->th = *th;
-		new->fn = start_routine;
-		new->name = backtrace_symbols(&new->fn, 1);
+	if (newthread) {
+		newthread->th = *th;
+		newthread->fn = start_routine;
+		newthread->name = backtrace_symbols(&new->fn, 1);
 		pthread_rwlock_wrlock(&_tlock);
-		list_insert(&_tlist, new);
+		list_insert(&_tlist, newthread);
 		++_tcount;
 		pthread_rwlock_unlock(&_tlock);
 	}



More information about the Cluster-cvs mailing list