You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sh...@apache.org on 2024/07/10 21:12:24 UTC
(trafficserver) 03/07: AVX-54729: fix memory leak
This is an automated email from the ASF dual-hosted git repository.
shinrich pushed a commit to branch avx-53179
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 2ea3642263d0ae6b23546ab511424fd669b8172b
Author: Kees Spoelstra <ks...@aviatrix.com>
AuthorDate: Tue Jul 2 12:39:58 2024 +0000
AVX-54729: fix memory leak
---
aviatrix/plugins/avx_policy_driver/web_filter.cc | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/aviatrix/plugins/avx_policy_driver/web_filter.cc b/aviatrix/plugins/avx_policy_driver/web_filter.cc
index 2596b267fa..3a90a3ee16 100644
--- a/aviatrix/plugins/avx_policy_driver/web_filter.cc
+++ b/aviatrix/plugins/avx_policy_driver/web_filter.cc
@@ -37,28 +37,28 @@ class PolicyHolder
{
public:
void
- SetPolicies(Layer7Config &new_config)
+ SetPolicies(std::shared_ptr<Layer7Config> new_config)
{
Dbg(dbg_ctl, "UpdatePolicy old generation=0x%x", this->generationNumber);
std::unique_lock<std::shared_mutex> lock(this->mutex);
- this->current_config = std::make_shared<Layer7Config>(new_config);
- auto it = new_config.mutable_policies()->begin();
+ this->current_config = new_config;
+ auto it = new_config->mutable_policies()->begin();
auto offset = policy_hit_counter_manager.CurrentOffset();
auto length = policy_hit_counter_manager.CurrentLength();
- auto send_old = policy_hit_counter_manager.CreateNew(new_config.policies_size());
+ auto send_old = policy_hit_counter_manager.CreateNew(new_config->policies_size());
uint32_t index = 0;
if (send_old && send_stats_callback) {
send_stats_callback(offset, length);
}
- while (it != new_config.mutable_policies()->end()) {
+ while (it != new_config->mutable_policies()->end()) {
policy_hit_counter_manager.ResetCounter(index++, it->id().a(), it->id().b());
it++;
}
- trafficFilters.load(new_config);
- webFilters.load(new_config);
+ trafficFilters.load(*new_config);
+ webFilters.load(*new_config);
this->generationNumber = this->generationNumber + 1;
}
@@ -167,6 +167,7 @@ IsPolicyLoaded()
}
static std::mutex load_policy_mutex;
+
bool
LoadPolicy(bool skip_if_exists)
{
@@ -180,7 +181,8 @@ LoadPolicy(bool skip_if_exists)
return true;
}
- Layer7Config *policyConfig = FetchLayer7Policy();
+ std::shared_ptr<Layer7Config> policyConfig(FetchLayer7Policy());
+
if (policyConfig != nullptr) {
if (current_config != nullptr) {
// ignore duplicates
@@ -190,7 +192,8 @@ LoadPolicy(bool skip_if_exists)
return true;
}
}
- activePolicy.SetPolicies(*policyConfig);
+ // SetPolicies will own the policy
+ activePolicy.SetPolicies(policyConfig);
}
return policyConfig != nullptr;
}