From 2dff7682621c09c58d222c02a7ea28d888c041e5 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 11 Feb 2019 10:17:02 -0300 Subject: [PATCH] Removes a memory leak on the JSON parser --- CHANGES | 2 ++ src/request_body_processor/json.cc | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 18ee5ed6..5377c5ca 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ v3.0.4 - YYYY-MMM-DD (to be released) ------------------------------------- + - Removes a memory leak on the JSON parser + [@zimmerle] - Enables LMDB on the regression tests. [Issue #2011, #2008 - @WGH-, @mdunc] - Fix: Extra whitespace in some configuration directives causing error diff --git a/src/request_body_processor/json.cc b/src/request_body_processor/json.cc index 1ac863ac..a6dd4ad4 100644 --- a/src/request_body_processor/json.cc +++ b/src/request_body_processor/json.cc @@ -87,10 +87,11 @@ bool JSON::processChunk(const char *buf, unsigned int size, std::string *err) { m_status = yajl_parse(m_handle, (const unsigned char *)buf, size); if (m_status != yajl_status_ok) { - const unsigned char *e = yajl_get_error(m_handle, 0, + unsigned char *e = yajl_get_error(m_handle, 0, (const unsigned char *)buf, size); /* We need to free the yajl error message later, how to do this? */ err->assign((const char *)e); + yajl_free_error(m_handle, e); return false; } @@ -102,9 +103,10 @@ bool JSON::complete(std::string *err) { /* Wrap up the parsing process */ m_status = yajl_complete_parse(m_handle); if (m_status != yajl_status_ok) { - const unsigned char *e = yajl_get_error(m_handle, 0, NULL, 0); + unsigned char *e = yajl_get_error(m_handle, 0, NULL, 0); /* We need to free the yajl error message later, how to do this? */ err->assign((const char *)e); + yajl_free_error(m_handle, e); return false; }