This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/8.0.x by this push:
     new 14cc190  Fixes memory leaks in header_rewrite
14cc190 is described below

commit 14cc19087971341de0b6e130c6cf8a072bc93970
Author: Randall Meyer <randallme...@yahoo.com>
AuthorDate: Mon Oct 22 16:27:52 2018 -0700

    Fixes memory leaks in header_rewrite
    
    (cherry picked from commit 8949c05368b3d1160da727d387a264c6ac3bf491)
    
    Conflicts:
        plugins/header_rewrite/value.cc
        plugins/header_rewrite/value.h
---
 plugins/header_rewrite/condition.h       |  6 ++++++
 plugins/header_rewrite/header_rewrite.cc |  4 +++-
 plugins/header_rewrite/ruleset.cc        |  2 ++
 plugins/header_rewrite/ruleset.h         | 13 ++++++++++++-
 plugins/header_rewrite/statement.h       |  1 +
 plugins/header_rewrite/value.h           |  6 ++++++
 6 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/plugins/header_rewrite/condition.h 
b/plugins/header_rewrite/condition.h
index ebafab4..73e3297 100644
--- a/plugins/header_rewrite/condition.h
+++ b/plugins/header_rewrite/condition.h
@@ -52,6 +52,12 @@ public:
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Condition");
   }
 
+  virtual ~Condition()
+  {
+    TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Condition");
+    delete _matcher;
+  }
+
   // Inline this, it's critical for speed (and only used twice)
   bool
   do_eval(const Resources &res)
diff --git a/plugins/header_rewrite/header_rewrite.cc 
b/plugins/header_rewrite/header_rewrite.cc
index b4aaacd..e95b53c 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -72,6 +72,7 @@ class RulesConfig
 public:
   RulesConfig()
   {
+    TSDebug(PLUGIN_NAME_DBG, "RulesConfig CTOR");
     memset(_rules, 0, sizeof(_rules));
     memset(_resids, 0, sizeof(_resids));
 
@@ -81,7 +82,8 @@ public:
 
   ~RulesConfig()
   {
-    for (int i = TS_HTTP_READ_REQUEST_HDR_HOOK; i < TS_HTTP_LAST_HOOK; ++i) {
+    TSDebug(PLUGIN_NAME_DBG, "RulesConfig DTOR");
+    for (int i = TS_HTTP_READ_REQUEST_HDR_HOOK; i <= TS_HTTP_LAST_HOOK; ++i) {
       delete _rules[i];
     }
     TSContDestroy(_cont);
diff --git a/plugins/header_rewrite/ruleset.cc 
b/plugins/header_rewrite/ruleset.cc
index 9dfe89c..f6d0140 100644
--- a/plugins/header_rewrite/ruleset.cc
+++ b/plugins/header_rewrite/ruleset.cc
@@ -49,6 +49,7 @@ RuleSet::add_condition(Parser &p, const char *filename, int 
lineno)
     TSDebug(PLUGIN_NAME, "   Adding condition: %%{%s} with arg: %s", 
p.get_op().c_str(), p.get_arg().c_str());
     c->initialize(p);
     if (!c->set_hook(_hook)) {
+      delete c;
       TSError("[%s] in %s:%d: can't use this condition in hook=%s: %%{%s} with 
arg: %s", PLUGIN_NAME, filename, lineno,
               TSHttpHookNameLookup(_hook), p.get_op().c_str(), 
p.get_arg().c_str());
       return false;
@@ -79,6 +80,7 @@ RuleSet::add_operator(Parser &p, const char *filename, int 
lineno)
     TSDebug(PLUGIN_NAME, "   Adding operator: %s(%s)", p.get_op().c_str(), 
p.get_arg().c_str());
     o->initialize(p);
     if (!o->set_hook(_hook)) {
+      delete o;
       TSDebug(PLUGIN_NAME, "in %s:%d: can't use this operator in hook=%s:  
%s(%s)", filename, lineno, TSHttpHookNameLookup(_hook),
               p.get_op().c_str(), p.get_arg().c_str());
       TSError("[%s] in %s:%d: can't use this operator in hook=%s:  %s(%s)", 
PLUGIN_NAME, filename, lineno,
diff --git a/plugins/header_rewrite/ruleset.h b/plugins/header_rewrite/ruleset.h
index 95b80d0..fcf74af 100644
--- a/plugins/header_rewrite/ruleset.h
+++ b/plugins/header_rewrite/ruleset.h
@@ -42,7 +42,18 @@ public:
       _hook(TS_HTTP_READ_RESPONSE_HDR_HOOK),
       _ids(RSRC_NONE),
       _opermods(OPER_NONE),
-      _last(false){};
+      _last(false)
+  {
+    TSDebug(PLUGIN_NAME_DBG, "RuleSet CTOR");
+  }
+
+  ~RuleSet()
+  {
+    TSDebug(PLUGIN_NAME_DBG, "RulesSet DTOR");
+    delete next;
+    delete _cond;
+    delete _oper;
+  }
 
   // No reason to inline these
   void append(RuleSet *rule);
diff --git a/plugins/header_rewrite/statement.h 
b/plugins/header_rewrite/statement.h
index 83ce00f..153ac93 100644
--- a/plugins/header_rewrite/statement.h
+++ b/plugins/header_rewrite/statement.h
@@ -105,6 +105,7 @@ public:
   {
     TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Statement");
     free_pdata();
+    delete _next;
   }
 
   // Private data
diff --git a/plugins/header_rewrite/value.h b/plugins/header_rewrite/value.h
index 11706bc..3f70bee 100644
--- a/plugins/header_rewrite/value.h
+++ b/plugins/header_rewrite/value.h
@@ -45,6 +45,12 @@ public:
     TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Value");
   }
 
+  virtual ~Value()
+  {
+    TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Value");
+    delete _cond_val;
+  }
+
   void
   set_value(const std::string &val)
   {

Reply via email to