summaryrefslogtreecommitdiffstats
path: root/lib/libkse
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2005-08-30 12:42:00 +0000
committerdeischen <deischen@FreeBSD.org>2005-08-30 12:42:00 +0000
commit91ca27dcf811d6921158321e8881a791aefd8064 (patch)
treec87b833ab649a3dbefbf6b57732337659cee2503 /lib/libkse
parent71ef4ac3b5e694f4e964561d3e3156e7cca5a36c (diff)
downloadFreeBSD-src-91ca27dcf811d6921158321e8881a791aefd8064.zip
FreeBSD-src-91ca27dcf811d6921158321e8881a791aefd8064.tar.gz
Allocate a thread's tcb last so it is easier to handle failures to
malloc() siginfo. PR: 85468
Diffstat (limited to 'lib/libkse')
-rw-r--r--lib/libkse/thread/thr_kern.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/libkse/thread/thr_kern.c b/lib/libkse/thread/thr_kern.c
index 85d9b33..d57665e 100644
--- a/lib/libkse/thread/thr_kern.c
+++ b/lib/libkse/thread/thr_kern.c
@@ -2365,6 +2365,11 @@ _thr_alloc(struct pthread *curthread)
if ((thread == NULL) &&
((thread = malloc(sizeof(struct pthread))) != NULL)) {
bzero(thread, sizeof(struct pthread));
+ thread->siginfo = calloc(_SIG_MAXSIG, sizeof(siginfo_t));
+ if (thread->siginfo == NULL) {
+ free(thread);
+ return (NULL);
+ }
if (curthread) {
_pthread_mutex_lock(&_tcb_mutex);
thread->tcb = _tcb_ctor(thread, 0 /* not initial tls */);
@@ -2372,27 +2377,23 @@ _thr_alloc(struct pthread *curthread)
} else {
thread->tcb = _tcb_ctor(thread, 1 /* initial tls */);
}
- thread->siginfo = calloc(_SIG_MAXSIG, sizeof(siginfo_t));
- if ((thread->tcb == NULL) || (thread->siginfo == NULL)) {
- if (thread->siginfo != NULL)
- free(thread->siginfo);
+ if (thread->tcb == NULL) {
+ free(thread->siginfo);
free(thread);
- thread = NULL;
- } else {
- /*
- * Initialize thread locking.
- * Lock initializing needs malloc, so don't
- * enter critical region before doing this!
- */
- if (_lock_init(&thread->lock, LCK_ADAPTIVE,
- _thr_lock_wait, _thr_lock_wakeup) != 0)
- PANIC("Cannot initialize thread lock");
- for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
- _lockuser_init(&thread->lockusers[i],
- (void *)thread);
- _LCK_SET_PRIVATE2(&thread->lockusers[i],
- (void *)thread);
- }
+ return (NULL);
+ }
+ /*
+ * Initialize thread locking.
+ * Lock initializing needs malloc, so don't
+ * enter critical region before doing this!
+ */
+ if (_lock_init(&thread->lock, LCK_ADAPTIVE,
+ _thr_lock_wait, _thr_lock_wakeup) != 0)
+ PANIC("Cannot initialize thread lock");
+ for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
+ _lockuser_init(&thread->lockusers[i], (void *)thread);
+ _LCK_SET_PRIVATE2(&thread->lockusers[i],
+ (void *)thread);
}
}
return (thread);
OpenPOWER on IntegriCloud