Reserve enough user request stack space in pthread_create.

Bug: 18830897
Change-Id: I1ba4aaeaf66a7ff99c5d82ad45469011171b0a3b
diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp
index 7c30e6e..a0a8df0 100644
--- a/libc/bionic/pthread_internals.cpp
+++ b/libc/bionic/pthread_internals.cpp
@@ -53,9 +53,9 @@
 
   // For threads using user allocated stack (including the main thread), the pthread_internal_t
   // can't be freed since it is on the stack.
-  if (free_thread && !(thread->attr.flags & PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK)) {
-    // Use one munmap to free the whole thread stack, including pthread_internal_t.
-    munmap(thread->attr.stack_base, thread->attr.stack_size);
+  if (free_thread && !thread->user_allocated_stack()) {
+    // Use one munmap to free allocated stack size, including thread stack and pthread_internal_t.
+    munmap(thread->attr.stack_base, thread->allocated_stack_size);
   }
 }