From 98d1aadb9e46be69ba23f287164b9dabf907102b Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Fri, 13 Dec 2019 10:07:51 -0700 Subject: [PATCH] GHI-599: avoid memory leak with default pattern matching and json formatting --- src/Val.cc | 4 ++-- src/Val.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 7f2cad149b..907a29d062 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -429,7 +429,7 @@ TableVal* Val::GetRecordFields() } // This is a static method in this file to avoid including json.hpp in Val.h since it's huge. -static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new RE_Matcher("^_")) +static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=nullptr) { // If the value wasn't set, return a nullptr. This will get turned into a 'null' in the json output. if ( ! val ) @@ -562,7 +562,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new auto field_name = rt->FieldName(i); std::string key_string; - if ( re->MatchAnywhere(field_name) != 0 ) + if ( re && re->MatchAnywhere(field_name) != 0 ) { StringVal blank(""); StringVal fn_val(field_name); diff --git a/src/Val.h b/src/Val.h index 09e8858e61..50b3b7a20f 100644 --- a/src/Val.h +++ b/src/Val.h @@ -348,7 +348,7 @@ public: TableVal* GetRecordFields(); - StringVal* ToJSON(bool only_loggable=false, RE_Matcher* re=new RE_Matcher("^_")); + StringVal* ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr); protected: