X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fthread%2Fpthread_create.c;h=d11dcfafa15153251b6f79b72dbc9772d512a7b0;hp=4c1decaa7ce5f660ace954a032fcd88751e603d6;hb=72768ea99e67162b7b42d9cd8917cf9a2c00f1f1;hpb=d5142642b8e6c45449158efdb8f8e87af4dafde8 diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 4c1decaa..d11dcfaf 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -142,14 +142,14 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp if (!tsd) { if (guard) { 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)) { munmap(map, size); - return EAGAIN; + goto fail; } } else { 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; if (!stack) stack = tsd - libc.tls_size; @@ -188,7 +188,7 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp if (ret < 0) { a_dec(&libc.threads_minus_1); - munmap(map, size); + if (map) munmap(map, size); return EAGAIN; } @@ -202,4 +202,7 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp *res = new; return 0; +fail: + __release_ptc(); + return EAGAIN; }