Skip to content

Commit 3e69567

Browse files
committed
Fix a memory leak for invalid std::regex in Schema.
1 parent a632160 commit 3e69567

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/rapidjson/schema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,10 +1150,12 @@ class Schema {
11501150
template <typename ValueType>
11511151
RegexType* CreatePattern(const ValueType& value) {
11521152
if (value.IsString())
1153+
RegexType *r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType)));
11531154
try {
1154-
return new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
1155+
return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
11551156
}
11561157
catch (const std::regex_error&) {
1158+
AllocatorType::Free(r);
11571159
}
11581160
return 0;
11591161
}

0 commit comments

Comments
 (0)