diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-04-09 02:57:38 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-04-09 02:57:38 (GMT) |
commit | 7fa242a44b47ce74d7246440b14571f7a5dd1b17 (patch) | |
tree | 968a9d50b23d7ef33cf37aaed77d23f0407fde7d /src | |
parent | c12f63214e9b7761d27e68353e4aaf1761c9cf88 (diff) | |
download | googletest-7fa242a44b47ce74d7246440b14571f7a5dd1b17.zip googletest-7fa242a44b47ce74d7246440b14571f7a5dd1b17.tar.gz googletest-7fa242a44b47ce74d7246440b14571f7a5dd1b17.tar.bz2 |
Makes the Python tests more stable (by Vlad Losev); fixes a memory leak in GetThreadCount() on Mac (by Vlad Losev); improves fuse_gtest_files.py to support fusing Google Mock files (by Zhanyong Wan).
Diffstat (limited to 'src')
-rw-r--r-- | src/gtest-port.cc | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 193f532..3c1e80c 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -45,6 +45,7 @@ #if GTEST_OS_MAC #include <mach/mach_init.h> #include <mach/task.h> +#include <mach/vm_map.h> #endif // GTEST_OS_MAC #ifdef _WIN32_WCE @@ -74,22 +75,37 @@ const int kStdErrFileno = 2; const int kStdErrFileno = STDERR_FILENO; #endif // _MSC_VER +#if GTEST_OS_MAC + // Returns the number of threads running in the process, or 0 to indicate that // we cannot detect it. size_t GetThreadCount() { -#if GTEST_OS_MAC + const task_t task = mach_task_self(); mach_msg_type_number_t thread_count; - thread_act_port_array_t thread_list; - kern_return_t status = task_threads(mach_task_self(), - &thread_list, &thread_count); - return status == KERN_SUCCESS ? static_cast<size_t>(thread_count) : 0; + thread_act_array_t thread_list; + const kern_return_t status = task_threads(task, &thread_list, &thread_count); + if (status == KERN_SUCCESS) { + // task_threads allocates resources in thread_list and we need to free them + // to avoid leaks. + vm_deallocate(task, + reinterpret_cast<vm_address_t>(thread_list), + sizeof(thread_t) * thread_count); + return static_cast<size_t>(thread_count); + } else { + return 0; + } +} + #else + +size_t GetThreadCount() { // There's no portable way to detect the number of threads, so we just // return 0 to indicate that we cannot detect it. return 0; -#endif // GTEST_OS_MAC } +#endif // GTEST_OS_MAC + #if GTEST_USES_POSIX_RE // Implements RE. Currently only needed for death tests. |