Commit 3e695676 authored by ylavic's avatar ylavic

Fix a memory leak for invalid std::regex in Schema.

parent a6321605
...@@ -1150,10 +1150,12 @@ private: ...@@ -1150,10 +1150,12 @@ private:
template <typename ValueType> template <typename ValueType>
RegexType* CreatePattern(const ValueType& value) { RegexType* CreatePattern(const ValueType& value) {
if (value.IsString()) if (value.IsString())
RegexType *r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType)));
try { 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&) { catch (const std::regex_error&) {
AllocatorType::Free(r);
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment