Merge pull request #1413 from ylavic/schema_regex_leak

Fix a memory leak for invalid std::regex in Schema.
This commit is contained in:
Milo Yip 2018-12-03 09:53:39 +08:00 committed by GitHub
commit 30d92a6399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1150,10 +1150,12 @@ private:
template <typename ValueType>
RegexType* CreatePattern(const ValueType& value) {
if (value.IsString())
RegexType *r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType)));
try {
return new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
}
catch (const std::regex_error&) {
AllocatorType::Free(r);
}
return 0;
}