summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-06-19 09:57:58 +0200
committerMichael Meeks <michael.meeks@collabora.com>2020-06-19 14:53:53 +0100
commit37db9d6876e6f64153d37d53bc0ab7022d8f2b68 (patch)
treef57eefb4b041b162a33b87d4e8f45ab2da86ad73 /tools/source
parentaac0764cae772d4ace7a279ae9800319dc61f46c (diff)
asan: need to use malloc instead of new for tools::JsonWriter
because the LOK API expects memory returned from those calls to be malloc'ed Change-Id: If6fbfb60c433bd6e58bc90a9a90a90663e2e1c60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96676 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/misc/json_writer.cxx16
1 files changed, 11 insertions, 5 deletions
diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx
index a233381038c4..5bba05a4c21d 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -19,9 +19,9 @@ constexpr int DEFAULT_BUFFER_SIZE = 2048;
JsonWriter::JsonWriter()
: mSpaceAllocated(DEFAULT_BUFFER_SIZE)
- , maBuffer(new char[mSpaceAllocated])
+ , mpBuffer(static_cast<char*>(malloc(mSpaceAllocated)))
, mStartNodeCount(0)
- , mPos(maBuffer.get())
+ , mPos(mpBuffer)
{
*mPos = '{';
++mPos;
@@ -29,7 +29,11 @@ JsonWriter::JsonWriter()
++mPos;
}
-JsonWriter::~JsonWriter() { assert(!maBuffer && "forgot to extract data?"); }
+JsonWriter::~JsonWriter()
+{
+ assert(!mpBuffer && "forgot to extract data?");
+ free(mpBuffer);
+}
ScopedJsonWriterNode JsonWriter::startNode(const char* pNodeName)
{
@@ -239,14 +243,16 @@ void JsonWriter::addCommaBeforeField()
char* JsonWriter::extractData()
{
assert(mStartNodeCount == 0 && "did not close all nodes");
- assert(maBuffer && "data already extracted");
+ assert(mpBuffer && "data already extracted");
// add closing brace
*mPos = '}';
++mPos;
// null-terminate
*mPos = 0;
mPos = nullptr;
- return maBuffer.release();
+ char* pRet = nullptr;
+ std::swap(pRet, mpBuffer);
+ return pRet;
}
} // namespace tools