From a0e5e68fdbf123d378f45a709315311f04a51594 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Fri, 28 Feb 2014 12:09:24 +0100 Subject: [PATCH] GenericDocument::Accept: deep-copy strings, if needed Instead of always just shallowly referencing the potentially allocated strings when calling the Handler::String function, request a copy in case the string has been allocated from an Allocator before. This is necessary to avoid double free()s of the string memory, especially when using the Handler to create a deep copy of a Value. The explicit comparison against '0' is done to suppress the warning C4800 on MSVC, see pah/rapidjson#5. --- include/rapidjson/document.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 8f2417b..9102915 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -579,7 +579,7 @@ int z = a[0u].GetInt(); // This works too. case kObjectType: handler.StartObject(); for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) { - handler.String(m->name.data_.s.str, m->name.data_.s.length, false); + handler.String(m->name.data_.s.str, m->name.data_.s.length, (m->name.flags_ & kCopyFlag) != 0); m->value.Accept(handler); } handler.EndObject(data_.o.size); @@ -593,7 +593,7 @@ int z = a[0u].GetInt(); // This works too. break; case kStringType: - handler.String(data_.s.str, data_.s.length, false); + handler.String(data_.s.str, data_.s.length, (flags_ & kCopyFlag) != 0); break; case kNumberType: