From b0800519b0dce9852ad77176a163cbd16e50a2c1 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 30 Aug 2018 17:13:44 -0400 Subject: [PATCH] Do not leak the Mach thread port in GetThreadCpuTimeNanos(). Bug: chromium:879307 Change-Id: Ia6b5b3ea4684354d8a21dc85e43f67166832cc19 Reviewed-on: https://webrtc-review.googlesource.com/96980 Reviewed-by: Ilya Nikolaevskiy Reviewed-by: Karl Wiberg Commit-Queue: Robert Sesek Cr-Commit-Position: refs/heads/master@{#24554} --- rtc_base/cpu_time.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rtc_base/cpu_time.cc b/rtc_base/cpu_time.cc index f25b50662e..de4a6bd684 100644 --- a/rtc_base/cpu_time.cc +++ b/rtc_base/cpu_time.cc @@ -16,6 +16,7 @@ #include #elif defined(WEBRTC_MAC) #include +#include #include #include #include @@ -81,10 +82,13 @@ int64_t GetThreadCpuTimeNanos() { RTC_LOG_ERR(LS_ERROR) << "clock_gettime() failed."; } #elif defined(WEBRTC_MAC) + mach_port_t thread_port = mach_thread_self(); thread_basic_info_data_t info; mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; - if (thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)&info, - &count) == KERN_SUCCESS) { + kern_return_t kr = + thread_info(thread_port, THREAD_BASIC_INFO, (thread_info_t)&info, &count); + mach_port_deallocate(mach_task_self(), thread_port); + if (kr == KERN_SUCCESS) { return info.user_time.seconds * kNumNanosecsPerSec + info.user_time.microseconds * kNumNanosecsPerMicrosec; } else {