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.
This commit is contained in:
Jon Siwek 2019-12-23 10:54:22 -08:00
parent 8cdcfad6d2
commit c0d6eb9efb

View file

@ -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<const char*>(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<const char*>(d.Bytes()), d.Len()));
break;
}