<rdar://problem/12219840>
Don't leak mach ports when calling "mach_thread_self()".
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@164152 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index 4b23ff4..400f493 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -39,6 +39,7 @@
#include <dispatch/dispatch.h>
#include <libproc.h>
#include <mach-o/dyld.h>
+#include <mach/mach_port.h>
#include <sys/sysctl.h>
@@ -430,7 +431,12 @@
Host::GetCurrentThreadID()
{
#if defined (__APPLE__)
- return ::mach_thread_self();
+ // Calling "mach_port_deallocate()" bumps the reference count on the thread
+ // port, so we need to deallocate it. mach_task_self() doesn't bump the ref
+ // count.
+ thread_port_t thread_self = mach_thread_self();
+ mach_port_deallocate(mach_task_self(), thread_self);
+ return thread_self;
#elif defined(__FreeBSD__)
return lldb::tid_t(pthread_getthreadid_np());
#else