From b0c96f9baf924a3ab37edf408cae1f2fb94ac843 Mon Sep 17 00:00:00 2001 From: ylavic Date: Sat, 1 Dec 2018 19:32:23 +0100 Subject: [PATCH] Use passed in allocator for internal regex parser. --- include/rapidjson/internal/regex.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/include/rapidjson/internal/regex.h b/include/rapidjson/internal/regex.h index de06718..377f86c 100644 --- a/include/rapidjson/internal/regex.h +++ b/include/rapidjson/internal/regex.h @@ -118,7 +118,8 @@ public: template friend class GenericRegexSearch; GenericRegex(const Ch* source, Allocator* allocator = 0) : - states_(allocator, 256), ranges_(allocator, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), + ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_), + states_(allocator_, 256), ranges_(allocator_, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(), anchorBegin_(), anchorEnd_() { GenericStringStream ss(source); @@ -126,7 +127,10 @@ public: Parse(ds); } - ~GenericRegex() {} + ~GenericRegex() + { + RAPIDJSON_DELETE(ownAllocator_); + } bool IsValid() const { return root_ != kRegexInvalidState; @@ -188,10 +192,9 @@ private: template void Parse(DecodedStream& ds) { - Allocator allocator; - Stack operandStack(&allocator, 256); // Frag - Stack operatorStack(&allocator, 256); // Operator - Stack atomCountStack(&allocator, 256); // unsigned (Atom per parenthesis) + Stack operandStack(allocator_, 256); // Frag + Stack operatorStack(allocator_, 256); // Operator + Stack atomCountStack(allocator_, 256); // unsigned (Atom per parenthesis) *atomCountStack.template Push() = 0; @@ -582,6 +585,8 @@ private: } } + Allocator* ownAllocator_; + Allocator* allocator_; Stack states_; Stack ranges_; SizeType root_;