mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 00:20:25 +08:00
<rdar://problem/12219840>
Don't leak mach ports when calling "mach_thread_self()". llvm-svn: 164152
This commit is contained in:
@@ -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 @@ lldb::tid_t
|
||||
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
|
||||
|
||||
@@ -185,13 +185,21 @@ _DNBLogThreaded (const char *format, ...)
|
||||
timersub (&tv, &g_timeval, &delta);
|
||||
}
|
||||
g_timeval = tv;
|
||||
|
||||
// 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();
|
||||
|
||||
_DNBLog (DNBLOG_FLAG_THREADED, "%u +%lu.%06u sec [%4.4x/%4.4x]: %s",
|
||||
++g_message_id,
|
||||
delta.tv_sec,
|
||||
delta.tv_usec,
|
||||
getpid(),
|
||||
mach_thread_self(),
|
||||
thread_self,
|
||||
arg_msg);
|
||||
|
||||
mach_port_deallocate(mach_task_self(), thread_self);
|
||||
free (arg_msg);
|
||||
}
|
||||
}
|
||||
@@ -230,13 +238,22 @@ _DNBLogThreadedIf (uint32_t log_bit, const char *format, ...)
|
||||
timersub (&tv, &g_timeval, &delta);
|
||||
}
|
||||
g_timeval = tv;
|
||||
_DNBLog (DNBLOG_FLAG_THREADED, "%u +%lu.%06u sec [%4.4x/%4.4x]: %s",
|
||||
|
||||
// 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();
|
||||
|
||||
_DNBLog (DNBLOG_FLAG_THREADED, "%u +%lu.%06u sec [%4.4x/%4.4x]: %s",
|
||||
++g_message_id,
|
||||
delta.tv_sec,
|
||||
delta.tv_usec,
|
||||
getpid(),
|
||||
mach_thread_self(),
|
||||
thread_self,
|
||||
arg_msg);
|
||||
|
||||
mach_port_deallocate(mach_task_self(), thread_self);
|
||||
|
||||
free (arg_msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user