You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/11/03 04:09:24 UTC
[trafficserver] branch 7.1.x updated: Fixes memory leaks in
header_rewrite
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/7.1.x by this push:
new 42af537 Fixes memory leaks in header_rewrite
42af537 is described below
commit 42af537ca3e44a2bb3fc39d9f0b807e97f86ddcc
Author: Randall Meyer <ra...@yahoo.com>
AuthorDate: Fri Nov 2 12:38:11 2018 -0700
Fixes memory leaks in header_rewrite
Correct botched backport
(cherry picked from commit 8f820c067f92590a8fece61cce98b92f24adb99b)
Conflicts:
plugins/header_rewrite/condition.h
plugins/header_rewrite/header_rewrite.cc
plugins/header_rewrite/ruleset.cc
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 eae138b..82c8546 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 fa8ef6e..85415db 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -72,6 +72,7 @@ class RulesConfig
public:
RulesConfig() : _ref_count(0)
{
+ TSDebug(PLUGIN_NAME_DBG, "RulesConfig CTOR");
memset(_rules, 0, sizeof(_rules));
memset(_resids, 0, sizeof(_resids));
@@ -114,7 +115,8 @@ public:
private:
~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 3f2821e..6604c5a 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;
TSError("[%s] in %s:%d: can't use this operator in hook=%s: %s(%s)", PLUGIN_NAME, filename, lineno,
TSHttpHookNameLookup(_hook), p.get_op().c_str(), p.get_arg().c_str());
return false;
diff --git a/plugins/header_rewrite/ruleset.h b/plugins/header_rewrite/ruleset.h
index f7e3523..73c774b 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 9ce70e9..65eb364 100644
--- a/plugins/header_rewrite/statement.h
+++ b/plugins/header_rewrite/statement.h
@@ -83,6 +83,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 67579e9..4bcee7c 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)
{