diff options
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread.c | 8 | ||||
-rw-r--r-- | lib/librthread/rthread_attr.c | 5 | ||||
-rw-r--r-- | lib/librthread/rthread_sync.c | 23 | ||||
-rw-r--r-- | lib/librthread/rthread_tls.c | 5 |
4 files changed, 15 insertions, 26 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index da0a7564591..066d1ebd4fd 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.38 2008/08/14 05:57:06 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.39 2008/10/13 05:42:46 kevlo Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -285,10 +285,9 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, if ((rc = _rthread_init())) return (rc); - thread = malloc(sizeof(*thread)); + thread = calloc(1, sizeof(*thread)); if (!thread) return (errno); - memset(thread, 0, sizeof(*thread)); thread->donesem.lock = _SPINLOCK_UNLOCKED; thread->flags_lock = _SPINLOCK_UNLOCKED; thread->fn = start_routine; @@ -423,10 +422,9 @@ pthread_cleanup_push(void (*fn)(void *), void *arg) struct rthread_cleanup_fn *clfn; pthread_t self = pthread_self(); - clfn = malloc(sizeof(*clfn)); + clfn = calloc(1, sizeof(*clfn)); if (!clfn) return; - memset(clfn, 0, sizeof(*clfn)); clfn->fn = fn; clfn->arg = arg; clfn->next = self->cleanup_fns; diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c index 6bc334ba92b..3d31ada7ab5 100644 --- a/lib/librthread/rthread_attr.c +++ b/lib/librthread/rthread_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_attr.c,v 1.8 2006/01/05 08:15:16 otto Exp $ */ +/* $OpenBSD: rthread_attr.c,v 1.9 2008/10/13 05:42:46 kevlo Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -60,10 +60,9 @@ pthread_attr_init(pthread_attr_t *attrp) { pthread_attr_t attr; - attr = malloc(sizeof(*attr)); + attr = calloc(1, sizeof(*attr)); if (!attr) return (errno); - memset(attr, 0, sizeof(*attr)); attr->stack_size = RTHREAD_STACK_SIZE_DEF; attr->guard_size = sysconf(_SC_PAGESIZE); attr->stack_size -= attr->guard_size; diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index 6755852502f..44a9eb6e8fd 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.19 2008/02/22 09:18:28 tedu Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.20 2008/10/13 05:42:46 kevlo Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -140,10 +140,9 @@ sem_init(sem_t *semp, int pshared, unsigned int value) return (-1); } - sem = malloc(sizeof(*sem)); + sem = calloc(1, sizeof(*sem)); if (!sem) return (-1); - memset(sem, 0, sizeof(*sem)); sem->value = value; *semp = sem; @@ -223,10 +222,9 @@ pthread_mutex_init(pthread_mutex_t *mutexp, const pthread_mutexattr_t *attr) { pthread_mutex_t mutex; - mutex = malloc(sizeof(*mutex)); + mutex = calloc(1, sizeof(*mutex)); if (!mutex) return (errno); - memset((void *)mutex, 0, sizeof(*mutex)); mutex->sem.lock = _SPINLOCK_UNLOCKED; mutex->sem.value = 1; /* unlocked */ mutex->type = attr ? (*attr)->type : PTHREAD_MUTEX_ERRORCHECK; @@ -325,10 +323,9 @@ pthread_mutexattr_init(pthread_mutexattr_t *attrp) { pthread_mutexattr_t attr; - attr = malloc(sizeof(*attr)); + attr = calloc(1, sizeof(*attr)); if (!attr) return (errno); - memset(attr, 0, sizeof(*attr)); attr->type = PTHREAD_MUTEX_ERRORCHECK; *attrp = attr; @@ -368,10 +365,9 @@ pthread_cond_init(pthread_cond_t *condp, const pthread_condattr_t *attrp) { pthread_cond_t cond; - cond = malloc(sizeof(*cond)); + cond = calloc(1, sizeof(*cond)); if (!cond) return (errno); - memset(cond, 0, sizeof(*cond)); cond->sem.lock = _SPINLOCK_UNLOCKED; *condp = cond; @@ -462,10 +458,9 @@ pthread_condattr_init(pthread_condattr_t *attrp) { pthread_condattr_t attr; - attr = malloc(sizeof(*attr)); + attr = calloc(1, sizeof(*attr)); if (!attr) return (errno); - memset(attr, 0, sizeof(*attr)); *attrp = attr; return (0); @@ -488,10 +483,9 @@ pthread_rwlock_init(pthread_rwlock_t *lockp, const pthread_rwlockattr_t *attrp) { pthread_rwlock_t lock; - lock = malloc(sizeof(*lock)); + lock = calloc(1, sizeof(*lock)); if (!lock) return (errno); - memset(lock, 0, sizeof(*lock)); lock->lock = _SPINLOCK_UNLOCKED; lock->sem.lock = _SPINLOCK_UNLOCKED; *lockp = lock; @@ -658,10 +652,9 @@ pthread_rwlockattr_init(pthread_rwlockattr_t *attrp) { pthread_rwlockattr_t attr; - attr = malloc(sizeof(*attr)); + attr = calloc(1, sizeof(*attr)); if (!attr) return (errno); - memset(attr, 0, sizeof(*attr)); *attrp = attr; return (0); diff --git a/lib/librthread/rthread_tls.c b/lib/librthread/rthread_tls.c index fb1c9074303..1e415872386 100644 --- a/lib/librthread/rthread_tls.c +++ b/lib/librthread/rthread_tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_tls.c,v 1.10 2005/12/22 20:48:57 brad Exp $ */ +/* $OpenBSD: rthread_tls.c,v 1.11 2008/10/13 05:42:46 kevlo Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -96,10 +96,9 @@ _rthread_findstorage(pthread_key_t key) break; } if (!rs) { - rs = malloc(sizeof(*rs)); + rs = calloc(1, sizeof(*rs)); if (!rs) return (NULL); - memset(rs, 0, sizeof(*rs)); rs->keyid = key; rs->data = NULL; rs->next = self->local_storage; |