summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-09-18 18:19:49 +0000
committerGreg Clayton <gclayton@apple.com>2012-09-18 18:19:49 +0000
commit813ddfcdd084ad1d979123784ea6ff1b813cf6b6 (patch)
tree593e59a5d1572fa3e685caa6ed96432d31a666e4 /lldb
parent63d2a23618759811ab83edfdb492b508ec4072fa (diff)
downloadbcm5719-llvm-813ddfcdd084ad1d979123784ea6ff1b813cf6b6.tar.gz
bcm5719-llvm-813ddfcdd084ad1d979123784ea6ff1b813cf6b6.zip
<rdar://problem/12219840>
Don't leak mach ports when calling "mach_thread_self()". llvm-svn: 164152
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Host/common/Host.cpp8
-rw-r--r--lldb/tools/debugserver/source/DNBLog.cpp23
2 files changed, 27 insertions, 4 deletions
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 4b23ff412ab..400f493d2c3 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/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 @@ 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
diff --git a/lldb/tools/debugserver/source/DNBLog.cpp b/lldb/tools/debugserver/source/DNBLog.cpp
index 664a03d657b..890e7e553ca 100644
--- a/lldb/tools/debugserver/source/DNBLog.cpp
+++ b/lldb/tools/debugserver/source/DNBLog.cpp
@@ -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);
}
}
OpenPOWER on IntegriCloud