This is an automated email from the ASF dual-hosted git repository. jonzeolla pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/metron-bro-plugin-kafka.git
The following commit(s) were added to refs/heads/master by this push: new b360b85 METRON-1910 bro plugin segfaults on src/KafkaWriter.cc:72 (JonZeolla) closes apache/metron-bro-plugin-kafka#20 b360b85 is described below commit b360b85e00a8d6b8db9c790c44a767a54c81eb2b Author: JonZeolla <zeo...@gmail.com> AuthorDate: Wed Feb 13 09:51:29 2019 -0500 METRON-1910 bro plugin segfaults on src/KafkaWriter.cc:72 (JonZeolla) closes apache/metron-bro-plugin-kafka#20 --- src/KafkaWriter.cc | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/KafkaWriter.cc b/src/KafkaWriter.cc index 79b5aa0..1d4a28a 100644 --- a/src/KafkaWriter.cc +++ b/src/KafkaWriter.cc @@ -20,15 +20,18 @@ using namespace logging; using namespace writer; +// The Constructor is called once for each log filter that uses this log writer. KafkaWriter::KafkaWriter(WriterFrontend* frontend): WriterBackend(frontend), formatter(NULL), producer(NULL), topic(NULL) { - // need thread-local copies of all user-defined settings coming from - // bro scripting land. accessing these is not thread-safe and 'DoInit' - // is potentially accessed from multiple threads. + /** + * We need thread-local copies of all user-defined settings coming from bro + * scripting land. accessing these is not thread-safe and 'DoInit' is + * potentially accessed from multiple threads. + */ // tag_json - thread local copy tag_json = BifConst::Kafka::tag_json; @@ -67,16 +70,13 @@ KafkaWriter::KafkaWriter(WriterFrontend* frontend): KafkaWriter::~KafkaWriter() { - - // Cleanup all the things - delete topic; - delete producer; - delete formatter; - delete conf; - delete topic_conf; - + // Cleanup must happen in DoFinish, not in the destructor } +/** + * DoInit is called once for each call to the constructor, but in a separate + * thread + */ bool KafkaWriter::DoInit(const WriterInfo& info, int num_fields, const threading::Field* const* fields) { // Timeformat object, default to TS_EPOCH @@ -87,11 +87,13 @@ bool KafkaWriter::DoInit(const WriterInfo& info, int num_fields, const threading topic_name = info.path; } - // format timestamps - // NOTE: This string comparision implementation is currently the necessary - // way to do it, as there isn't a way to pass the Bro enum into C++ enum. - // This makes the user interface consistent with the existing Bro Logging - // configuration for the ASCII log output. + /** + * Format the timestamps + * NOTE: This string comparision implementation is currently the necessary + * way to do it, as there isn't a way to pass the Bro enum into C++ enum. + * This makes the user interface consistent with the existing Bro Logging + * configuration for the ASCII log output. + */ if ( strcmp(json_timestamps.c_str(), "JSON::TS_EPOCH") == 0 ) { tf = threading::formatter::JSON::TS_EPOCH; } @@ -177,7 +179,8 @@ bool KafkaWriter::DoInit(const WriterInfo& info, int num_fields, const threading /** * Writer-specific method called just before the threading system is * going to shutdown. It is assumed that once this messages returns, - * the thread can be safely terminated. + * the thread can be safely terminated. As such, all resources created must be + * removed here. */ bool KafkaWriter::DoFinish(double network_time) { @@ -202,6 +205,8 @@ bool KafkaWriter::DoFinish(double network_time) delete topic; delete producer; delete formatter; + delete conf; + delete topic_conf; return success; }