Do not use shared PCRE2 match data

The match data needs to be unique for each thread, so for the time
being it is created whenever it is needed. A more performant (although
possibly to a negigible amount) solution would be to have a separate
match data for each thread, but that will have to wait for 2.2.
This commit is contained in:
Johan Wikman
2017-03-21 12:50:19 +02:00
parent 117534d288
commit 15a22ec295

View File

@ -109,7 +109,6 @@ class AccountRegexp : public MaskingRules::Rule::Account
public:
~AccountRegexp()
{
pcre2_match_data_free(m_pData);
pcre2_code_free(m_pCode);
}
@ -126,26 +125,12 @@ public:
{
Closer<pcre2_code*> code(pCode);
pcre2_match_data* pData = pcre2_match_data_create_from_pattern(pCode, NULL);
sAccount = shared_ptr<AccountRegexp>(new AccountRegexp(user, host, pCode));
if (pData)
{
Closer<pcre2_match_data*> data(pData);
sAccount = shared_ptr<AccountRegexp>(new AccountRegexp(user, host, pCode, pData));
// Ownership of pCode and pData has been moved to the
// AccountRegexp instance.
data.release();
// Ownership of pCode has been moved to the AccountRegexp object.
code.release();
}
else
{
MXS_ERROR("PCRE2 match data creation failed. Most likely due to a "
"lack of available memory.");
}
}
else
{
PCRE2_UCHAR errbuf[512];
pcre2_get_error_message(errcode, errbuf, sizeof(errbuf));
@ -171,20 +156,31 @@ public:
ss_dassert(zUser);
ss_dassert(zHost);
return
(m_user.empty() || (m_user == zUser)) &&
pcre2_match(m_pCode, (PCRE2_SPTR)zHost, 0, 0, 0, m_pData, NULL) >= 0;
bool rv = (m_user.empty() || (m_user == zUser));
if (rv)
{
ss_dassert(m_pCode);
pcre2_match_data* pData = pcre2_match_data_create_from_pattern(m_pCode, NULL);
if (pData)
{
Closer<pcre2_match_data*> data(pData);
rv = (pcre2_match(m_pCode, (PCRE2_SPTR)zHost, 0, 0, 0, pData, NULL) >= 0);
}
}
return rv;
}
private:
AccountRegexp(const string& user,
const string& host,
pcre2_code* pCode,
pcre2_match_data* pData)
pcre2_code* pCode)
: m_user(user)
, m_host(host)
, m_pCode(pCode)
, m_pData(pData)
{
}
@ -195,7 +191,6 @@ private:
string m_user;
string m_host;
pcre2_code* m_pCode;
pcre2_match_data* m_pData;
};
/**