METRON-1910 bro plugin segfaults on src/KafkaWriter.cc:72 (JonZeolla) closes apache/metron-bro-plugin-kafka#20
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()
 {
-
-    // 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 @@
         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 @@
 /**
  * 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 @@
     delete topic;
     delete producer;
     delete formatter;
+    delete conf;
+    delete topic_conf;
 
     return success;
 }