From c0d6eb9efbc133c320a963729e99251d4b6952e3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 23 Dec 2019 10:54:22 -0800 Subject: [PATCH] Fix malloc/delete mismatch in JSON formatting ODesc allocated with malloc() and BroString deallocated with delete[], but really the intermediate BroString wasn't even needed when copying into std::string. --- src/Val.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 907a29d062..53aecb0bbb 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -479,11 +479,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=nul ODesc d; d.SetStyle(RAW_STYLE); val->Describe(&d); - - auto* bs = new BroString(1, d.TakeBytes(), d.Len()); - j = string((char*)bs->Bytes(), bs->Len()); - - delete bs; + j = string(reinterpret_cast(d.Bytes()), d.Len()); break; } @@ -495,11 +491,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=nul ODesc d; d.SetStyle(RAW_STYLE); val->Describe(&d); - - auto* bs = new BroString(1, d.TakeBytes(), d.Len()); - j = json_escape_utf8(string((char*)bs->Bytes(), bs->Len())); - - delete bs; + j = json_escape_utf8(string(reinterpret_cast(d.Bytes()), d.Len())); break; }