trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject trafficserver git commit: CID 1328817: Resource leaks (CTOR_DTOR_LEAK) in multiplexer plugin
Date Tue, 10 Nov 2015 04:07:02 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master df48fade2 -> 0f8236763


CID 1328817: Resource leaks (CTOR_DTOR_LEAK) in multiplexer plugin

This closes #316


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0f823676
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0f823676
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0f823676

Branch: refs/heads/master
Commit: 0f823676361d2095f4e24b9fc97ef3dde4aadc85
Parents: df48fad
Author: Daniel Vitor Morilha <dmorilha@gmail.com>
Authored: Mon Nov 9 20:03:07 2015 -0800
Committer: Bryan Call <bcall@apache.org>
Committed: Mon Nov 9 20:03:07 2015 -0800

----------------------------------------------------------------------
 plugins/experimental/multiplexer/dispatch.cc | 33 +++++++++++++++++------
 plugins/experimental/multiplexer/dispatch.h  |  5 +++-
 2 files changed, 29 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0f823676/plugins/experimental/multiplexer/dispatch.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/multiplexer/dispatch.cc b/plugins/experimental/multiplexer/dispatch.cc
index fe44b0b..585b2cf 100644
--- a/plugins/experimental/multiplexer/dispatch.cc
+++ b/plugins/experimental/multiplexer/dispatch.cc
@@ -36,19 +36,37 @@ extern Statistics statistics;
 extern size_t timeout;
 
 Request::Request(const std::string &h, const TSMBuffer b, const TSMLoc l)
-  : host(h), length(TSHttpHdrLengthGet(b, l)),
-    // coverity[ctor_dtor_leak]
-    io(new ats::io::IO())
+  : host(h), length(TSHttpHdrLengthGet(b, l)), io(new ats::io::IO())
 {
   assert(!host.empty());
   assert(b != NULL);
   assert(l != NULL);
-  assert(io != NULL);
   assert(length > 0);
+  assert(io.get() != NULL);
   TSHttpHdrPrint(b, l, io->buffer);
   assert(length == TSIOBufferReaderAvail(io->reader));
 }
 
+Request::Request(const Request &r) : host(r.host), length(r.length), io(const_cast<Request
&>(r).io)
+{
+  assert(!host.empty());
+  assert(length > 0);
+  assert(io.get() != NULL);
+  assert(r.io.get() != NULL);
+}
+
+Request &Request::operator=(Request &r)
+{
+  host = r.host;
+  length = r.length;
+  io = r.io;
+  assert(!host.empty());
+  assert(length > 0);
+  assert(io.get() != NULL);
+  assert(r.io.get() == NULL);
+  return *this;
+}
+
 uint64_t
 copy(const TSIOBufferReader &r, const TSIOBuffer b)
 {
@@ -218,7 +236,7 @@ addBody(Requests &r, const TSIOBufferReader re)
   }
   assert(length > 0);
   for (; iterator != end; ++iterator) {
-    assert(iterator->io != NULL);
+    assert(iterator->io.get() != NULL);
     const int64_t size = copy(re, iterator->io->buffer);
     assert(size == length);
     iterator->length += size;
@@ -231,7 +249,7 @@ dispatch(Requests &r, const int t)
   Requests::iterator iterator = r.begin();
   const Requests::iterator end = r.end();
   for (; iterator != end; ++iterator) {
-    assert(iterator->io != NULL);
+    assert(iterator->io.get() != NULL);
     if (TSIsDebugTagSet(PLUGIN_TAG) > 0) {
       TSDebug(PLUGIN_TAG, "Dispatching %i bytes to \"%s\"", iterator->length, iterator->host.c_str());
       std::string b;
@@ -239,8 +257,7 @@ dispatch(Requests &r, const int t)
       assert(b.size() == static_cast<uint64_t>(iterator->length));
       TSDebug(PLUGIN_TAG, "%s", b.c_str());
     }
-    ats::get(iterator->io, iterator->length, Handler(iterator->host), t);
     // forwarding iterator->io pointer ownership
-    iterator->io = NULL;
+    ats::get(iterator->io.release(), iterator->length, Handler(iterator->host),
t);
   }
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0f823676/plugins/experimental/multiplexer/dispatch.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/multiplexer/dispatch.h b/plugins/experimental/multiplexer/dispatch.h
index e152742..61c79a8 100644
--- a/plugins/experimental/multiplexer/dispatch.h
+++ b/plugins/experimental/multiplexer/dispatch.h
@@ -24,6 +24,7 @@
 #define DISPATCH_H
 
 #include <assert.h>
+#include <memory>
 #include <string>
 #include <ts/ts.h>
 #include <vector>
@@ -50,9 +51,11 @@ typedef std::vector<std::string> Origins;
 struct Request {
   std::string host;
   int length;
-  ats::io::IO *io;
+  std::auto_ptr<ats::io::IO> io;
 
   Request(const std::string &, const TSMBuffer, const TSMLoc);
+  Request(const Request &);
+  Request &operator=(Request &);
 };
 
 typedef std::vector<Request> Requests;


Mime
View raw message