This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 4c9c7c63dc Fix crash by including remap files with named filters
(#11997)
4c9c7c63dc is described below
commit 4c9c7c63dcddc60c473509f66a262a09593f9b2e
Author: Masaori Koshiba <[email protected]>
AuthorDate: Wed Jan 29 08:04:19 2025 +0900
Fix crash by including remap files with named filters (#11997)
* Fix crash by including remap files with named filters
* Fix unit test
---
include/proxy/http/remap/RemapConfig.h | 3 +++
src/proxy/http/remap/RemapConfig.cc | 22 ++++++++++++++--------
src/proxy/http/remap/unit-tests/test_RemapRules.cc | 3 +++
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/include/proxy/http/remap/RemapConfig.h
b/include/proxy/http/remap/RemapConfig.h
index b303ba2dd0..8456dd846c 100644
--- a/include/proxy/http/remap/RemapConfig.h
+++ b/include/proxy/http/remap/RemapConfig.h
@@ -70,6 +70,9 @@ struct BUILD_TABLE_INFO {
// Clear the argument vector.
void reset();
+ // Free acl_filter_rule in the list
+ void clear_acl_rules_list();
+
// noncopyable
BUILD_TABLE_INFO(const BUILD_TABLE_INFO &) = delete; // disabled
BUILD_TABLE_INFO &operator=(const BUILD_TABLE_INFO &) = delete; // disabled
diff --git a/src/proxy/http/remap/RemapConfig.cc
b/src/proxy/http/remap/RemapConfig.cc
index c702d98a3f..9a5d8cb64e 100644
--- a/src/proxy/http/remap/RemapConfig.cc
+++ b/src/proxy/http/remap/RemapConfig.cc
@@ -97,14 +97,6 @@ BUILD_TABLE_INFO::BUILD_TABLE_INFO()
BUILD_TABLE_INFO::~BUILD_TABLE_INFO()
{
this->reset();
-
- // clean up any leftover named filter rules
- auto *rp = rules_list;
- while (rp != nullptr) {
- auto *tmp = rp->next;
- delete rp;
- rp = tmp;
- }
}
void
@@ -115,6 +107,18 @@ BUILD_TABLE_INFO::reset()
clear_xstr_array(this->argv, sizeof(this->argv) / sizeof(char *));
}
+void
+BUILD_TABLE_INFO::clear_acl_rules_list()
+{
+ // clean up any leftover named filter rules
+ auto *rp = rules_list;
+ while (rp != nullptr) {
+ auto *tmp = rp->next;
+ delete rp;
+ rp = tmp;
+ }
+}
+
static const char *
process_filter_opt(url_mapping *mp, const BUILD_TABLE_INFO *bti, char
*errStrBuf, int errStrBufSize)
{
@@ -1490,5 +1494,7 @@ remap_parse_config(const char *path, UrlRewrite *rewrite)
* accordingly notify all plugins that we are done */
rewrite->pluginFactory.indicatePostReload(status);
+ bti.clear_acl_rules_list();
+
return status;
}
diff --git a/src/proxy/http/remap/unit-tests/test_RemapRules.cc
b/src/proxy/http/remap/unit-tests/test_RemapRules.cc
index 0cec0133d3..b09c7a1c89 100644
--- a/src/proxy/http/remap/unit-tests/test_RemapRules.cc
+++ b/src/proxy/http/remap/unit-tests/test_RemapRules.cc
@@ -35,6 +35,8 @@
#include "swoc/swoc_file.h"
#include "ts/apidefs.h"
#include "tscore/BaseLogFile.h"
+#include "tsutil/PostScript.h"
+
#include <memory>
#define CATCH_CONFIG_MAIN /* include main function */
@@ -83,6 +85,7 @@ SCENARIO("Parsing ACL named filters", "[proxy][remap]")
GIVEN("Named filter definitions with multiple actions")
{
BUILD_TABLE_INFO bti{};
+ ts::PostScript acl_rules_defer([&]() -> void {
bti.clear_acl_rules_list(); });
UrlRewrite rewrite{};
bti.rewrite = &rewrite;