cmcfarlen commented on code in PR #12594:
URL: https://github.com/apache/trafficserver/pull/12594#discussion_r2450024771
##########
plugins/experimental/maxmind_acl/mmdb.cc:
##########
@@ -399,19 +399,11 @@ Acl::parseregex(const YAML::Node ®ex, bool allow)
plugin_regex temp;
auto temprule = i.as<std::vector<std::string>>();
temp._regex_s = temprule.back();
- const char *error;
- int erroffset;
- temp._rex = pcre_compile(temp._regex_s.c_str(), 0, &error,
&erroffset, nullptr);
-
- // Compile the regex for this set of countries
- if (nullptr != temp._rex) {
- temp._extra = pcre_study(temp._rex, 0, &error);
- if ((nullptr == temp._extra) && error && (*error != 0)) {
- TSError("[%s] Failed to study regular expression in %s:%s",
PLUGIN_NAME, temp._regex_s.c_str(), error);
- return;
- }
- } else {
- TSError("[%s] Failed to compile regular expression in %s: %s",
PLUGIN_NAME, temp._regex_s.c_str(), error);
+ std::string error;
+ int erroroffset = 0;
+ temp._rex = new Regex();
+ if (!temp._rex->compile(temp._regex_s, error, erroroffset, 0)) {
+ TSError("[%s] Failed to compile regular expression in %s",
PLUGIN_NAME, temp._regex_s.c_str());
Review Comment:
Should delete `temp._rex` here since this returns without saving it.
##########
plugins/experimental/maxmind_acl/mmdb.h:
##########
@@ -71,6 +66,20 @@ class Acl
if (db_loaded) {
MMDB_close(&_mmdb);
}
+ for (auto &i : allow_regex) {
+ for (auto &y : i.second) {
+ if (y._rex != nullptr) {
+ delete y._rex;
+ }
+ }
+ }
+ for (auto &i : deny_regex) {
+ for (auto &y : i.second) {
+ if (y._rex != nullptr) {
+ delete y._rex;
+ }
+ }
+ }
Review Comment:
Its seems like the regex could be added to multiple or these vectors. Is it
safe to delete them repeatedly if the pointers are copied? Seems strange.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]