THRIFT-3943: resolve some high severity outstanding defects identified by coverity scan
Clients: C++, Lua
Patch: James E. King, III <jim.king@simplivity.com>

This closes #1109
diff --git a/lib/cpp/test/TFileTransportTest.cpp b/lib/cpp/test/TFileTransportTest.cpp
index 8551b78..82e84e8 100644
--- a/lib/cpp/test/TFileTransportTest.cpp
+++ b/lib/cpp/test/TFileTransportTest.cpp
@@ -189,7 +189,7 @@
 
   unsigned int num_over = 0;
   for (unsigned int n = 0; n < NUM_ITERATIONS; ++n) {
-    ftruncate(f.getFD(), 0);
+    BOOST_CHECK_EQUAL(0, ftruncate(f.getFD(), 0));
 
     TFileTransport* transport = new TFileTransport(f.getPath());
 
@@ -392,21 +392,21 @@
 #ifdef BOOST_TEST_DYN_LINK
 static int myArgc = 0;
 static char **myArgv = NULL;
- 
+
 bool init_unit_test_suite() {
   boost::unit_test::framework::master_test_suite().p_name.value = "TFileTransportTest";
- 
+
   // Parse arguments
   parse_args(myArgc,myArgv);
   return true;
 }
- 
+
 int main( int argc, char* argv[] ) {
   myArgc = argc;
   myArgv = argv;
   return ::boost::unit_test::unit_test_main(&init_unit_test_suite,argc,argv);
 }
-#else 
+#else
 boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
   boost::unit_test::framework::master_test_suite().p_name.value = "TFileTransportTest";
 
@@ -414,4 +414,4 @@
   parse_args(argc, argv);
   return NULL;
 }
-#endif
\ No newline at end of file
+#endif
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
index 635c8a2..3ad14ca 100644
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -102,7 +102,7 @@
 
     PlatformThreadFactory threadFactory = PlatformThreadFactory();
 
-    Monitor* monitor = new Monitor();
+    shared_ptr<Monitor> monitor(new Monitor);
 
     for (int lix = 0; lix < loop; lix++) {
 
diff --git a/lib/cpp/test/concurrency/ThreadManagerTests.h b/lib/cpp/test/concurrency/ThreadManagerTests.h
index 08e8179..b196813 100644
--- a/lib/cpp/test/concurrency/ThreadManagerTests.h
+++ b/lib/cpp/test/concurrency/ThreadManagerTests.h
@@ -45,7 +45,7 @@
 
   public:
     Task(Monitor& monitor, size_t& count, int64_t timeout)
-      : _monitor(monitor), _count(count), _timeout(timeout), _done(false) {}
+      : _monitor(monitor), _count(count), _timeout(timeout), _startTime(0), _endTime(0), _done(false) {}
 
     void run() {
 
diff --git a/lib/cpp/test/concurrency/TimerManagerTests.h b/lib/cpp/test/concurrency/TimerManagerTests.h
index f4600fc..c6fa4cf 100644
--- a/lib/cpp/test/concurrency/TimerManagerTests.h
+++ b/lib/cpp/test/concurrency/TimerManagerTests.h
@@ -42,6 +42,7 @@
     Task(Monitor& monitor, int64_t timeout)
       : _timeout(timeout),
         _startTime(Util::currentTime()),
+        _endTime(0),
         _monitor(monitor),
         _success(false),
         _done(false) {}
diff --git a/lib/cpp/test/processor/EventLog.cpp b/lib/cpp/test/processor/EventLog.cpp
index d4b8372..360307a 100644
--- a/lib/cpp/test/processor/EventLog.cpp
+++ b/lib/cpp/test/processor/EventLog.cpp
@@ -19,22 +19,26 @@
 #include "EventLog.h"
 
 #include <stdarg.h>
+#include <stdlib.h>
 
 using namespace std;
 using namespace apache::thrift::concurrency;
 
 namespace {
 
+// Define environment variable DEBUG_EVENTLOG to enable debug logging
+// ex: $ DEBUG_EVENTLOG=1 processor_test
+static const char * DEBUG_EVENTLOG = getenv("DEBUG_EVENTLOG");
+
 void debug(const char* fmt, ...) {
-  // Comment out this return to enable debug logs from the test code.
-  return;
+  if (DEBUG_EVENTLOG) {
+    va_list ap;
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
 
-  va_list ap;
-  va_start(ap, fmt);
-  vfprintf(stderr, fmt, ap);
-  va_end(ap);
-
-  fprintf(stderr, "\n");
+    fprintf(stderr, "\n");
+  }
 }
 }