libWebRTC GetThreadCpuTimeNanos() leaks mach_ports
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2018 00:48:04 +0000 (00:48 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2018 00:48:04 +0000 (00:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187403
<rdar://problem/41741599>

Reviewed by Simon Fraser.

* Source/webrtc/rtc_base/cpu_time.cc: Call mach_port_deallocate to
to ensure mach_port is deleted.
* libwebrtc.xcodeproj/project.pbxproj: Stop compiling this file since
this is not used except by libwebrtc tests.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233609 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Source/webrtc/rtc_base/cpu_time.cc
Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj

index e297d08..2458a90 100644 (file)
@@ -1,3 +1,16 @@
+2018-07-06  Youenn Fablet  <youenn@apple.com>
+
+        libWebRTC GetThreadCpuTimeNanos() leaks mach_ports
+        https://bugs.webkit.org/show_bug.cgi?id=187403
+        <rdar://problem/41741599>
+
+        Reviewed by Simon Fraser.
+
+        * Source/webrtc/rtc_base/cpu_time.cc: Call mach_port_deallocate to
+        to ensure mach_port is deleted.
+        * libwebrtc.xcodeproj/project.pbxproj: Stop compiling this file since
+        this is not used except by libwebrtc tests.
+
 2018-07-04  Thibault Saunier  <tsaunier@igalia.com>
 
         [libwebrtc] Allow IP mismatch for local connections on localhost
index 6c22880..020cc72 100644 (file)
@@ -18,9 +18,9 @@
 #include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/times.h>
-#include <mach/thread_info.h>
 #include <mach/thread_act.h>
-#include <mach/mach_init.h>
+#include <mach/thread_info.h>
+#include <mach/mach_port.h>
 #include <unistd.h>
 #elif defined(WEBRTC_WIN)
 #include <windows.h>
@@ -83,8 +83,10 @@ int64_t GetThreadCpuTimeNanos() {
 #elif defined(WEBRTC_MAC)
   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) {
+  auto port = mach_thread_self();
+  auto result = thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count);
+  mach_port_deallocate(mach_task_self(), port);
+  if (result == KERN_SUCCESS) {
     return info.user_time.seconds * kNumNanosecsPerSec +
            info.user_time.microseconds * kNumNanosecsPerMicrosec;
   } else {
index 034e57b..1062ba6 100644 (file)
                413A23071FE18E0700373E99 /* httpbase.cc in Sources */ = {isa = PBXBuildFile; fileRef = 413A21B21FE18D9700373E99 /* httpbase.cc */; };
                413A23091FE18E0700373E99 /* memory_usage.h in Headers */ = {isa = PBXBuildFile; fileRef = 413A21B41FE18D9700373E99 /* memory_usage.h */; };
                413A230A1FE18E0700373E99 /* ptr_util.h in Headers */ = {isa = PBXBuildFile; fileRef = 413A21B51FE18D9800373E99 /* ptr_util.h */; };
-               413A230C1FE18E0700373E99 /* cpu_time.cc in Sources */ = {isa = PBXBuildFile; fileRef = 413A21B81FE18D9900373E99 /* cpu_time.cc */; };
                413A230D1FE18E0700373E99 /* rate_statistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 413A21B91FE18D9A00373E99 /* rate_statistics.h */; };
                413A230F1FE18E0700373E99 /* rtccertificate.cc in Sources */ = {isa = PBXBuildFile; fileRef = 413A21BB1FE18D9B00373E99 /* rtccertificate.cc */; };
                413A23101FE18E0700373E99 /* fakeclock.cc in Sources */ = {isa = PBXBuildFile; fileRef = 413A21BC1FE18D9B00373E99 /* fakeclock.cc */; };
                                5CDD907A1E43D15C00621E92 /* covariance_matrix_generator.cc in Sources */,
                                5C4B4CCA1E4320A9002651C8 /* cpu_features.cc in Sources */,
                                5C4B4CCB1E4320A9002651C8 /* cpu_info.cc in Sources */,
-                               413A230C1FE18E0700373E99 /* cpu_time.cc in Sources */,
                                5CDD87B11E43BC0500621E92 /* crc.c in Sources */,
                                413A23431FE18E0700373E99 /* crc32.cc in Sources */,
                                5CDD8B8B1E43C2B500621E92 /* create_augmented_vec.c in Sources */,