fix stale locks left behind when pthread_create fails

this bug seems to have been around a long time.
This commit is contained in:
Rich Felker 2013-02-01 22:25:19 -05:00
parent 077549e0d4
commit 72768ea99e
1 changed files with 6 additions and 3 deletions

View File

@ -142,14 +142,14 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp
if (!tsd) { if (!tsd) {
if (guard) { if (guard) {
map = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); map = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
if (map == MAP_FAILED) return EAGAIN; if (map == MAP_FAILED) goto fail;
if (mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)) { if (mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)) {
munmap(map, size); munmap(map, size);
return EAGAIN; goto fail;
} }
} else { } else {
map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
if (map == MAP_FAILED) return EAGAIN; if (map == MAP_FAILED) goto fail;
} }
tsd = map + size - __pthread_tsd_size; tsd = map + size - __pthread_tsd_size;
if (!stack) stack = tsd - libc.tls_size; if (!stack) stack = tsd - libc.tls_size;
@ -202,4 +202,7 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp
*res = new; *res = new;
return 0; return 0;
fail:
__release_ptc();
return EAGAIN;
} }