summaryrefslogtreecommitdiff
path: root/src/gtest-port.cc
diff options
context:
space:
mode:
authorvladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-03 02:27:02 +0000
committervladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-03 02:27:02 +0000
commit673a0cb9079f8f37bd61588a3160e12daf70ec44 (patch)
treeaf456a0d47524f6bb5cbb49d160e0aaf60110daf /src/gtest-port.cc
parent8236131e25705a809d496672a3819e1741166c4b (diff)
downloadgtest-673a0cb9079f8f37bd61588a3160e12daf70ec44.tar.gz
gtest-673a0cb9079f8f37bd61588a3160e12daf70ec44.tar.bz2
gtest-673a0cb9079f8f37bd61588a3160e12daf70ec44.tar.xz
Adds Solaris support (by Hady Zalek)
git-svn-id: http://googletest.googlecode.com/svn/trunk@371 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'src/gtest-port.cc')
-rw-r--r--src/gtest-port.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index 957595a..7d89e26 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -111,8 +111,14 @@ size_t GetThreadCount() {
// Implements RE. Currently only needed for death tests.
RE::~RE() {
- regfree(&partial_regex_);
- regfree(&full_regex_);
+ if (is_valid_) {
+ // regfree'ing an invalid regex might crash because the content
+ // of the regex is undefined. Since the regex's are essentially
+ // the same, one cannot be valid (or invalid) without the other
+ // being so too.
+ regfree(&partial_regex_);
+ regfree(&full_regex_);
+ }
free(const_cast<char*>(pattern_));
}
@@ -152,9 +158,10 @@ void RE::Init(const char* regex) {
// Some implementation of POSIX regex (e.g. on at least some
// versions of Cygwin) doesn't accept the empty string as a valid
// regex. We change it to an equivalent form "()" to be safe.
- const char* const partial_regex = (*regex == '\0') ? "()" : regex;
- is_valid_ = (regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0)
- && is_valid_;
+ if (is_valid_) {
+ const char* const partial_regex = (*regex == '\0') ? "()" : regex;
+ is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
+ }
EXPECT_TRUE(is_valid_)
<< "Regular expression \"" << regex
<< "\" is not a valid POSIX Extended regular expression.";