summaryrefslogtreecommitdiff
path: root/src/gtest-port.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-04-09 02:57:38 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-04-09 02:57:38 +0000
commit767998dfadaf87c1193d51cf5847a7f147c6e1f7 (patch)
tree968a9d50b23d7ef33cf37aaed77d23f0407fde7d /src/gtest-port.cc
parent1b171100b3341c01fb377f8202d9eaccbeec1f55 (diff)
downloadgtest-767998dfadaf87c1193d51cf5847a7f147c6e1f7.tar.gz
gtest-767998dfadaf87c1193d51cf5847a7f147c6e1f7.tar.bz2
gtest-767998dfadaf87c1193d51cf5847a7f147c6e1f7.tar.xz
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).
git-svn-id: http://googletest.googlecode.com/svn/trunk@238 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'src/gtest-port.cc')
-rw-r--r--src/gtest-port.cc28
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.