Specify deleter function for regex_t unique_ptr (#2536)

This commit is contained in:
Andrew Gaul 2024-10-06 18:30:22 +09:00 committed by GitHub
parent e80de15cc6
commit bbbb2d0908
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 9 deletions

View File

@ -119,7 +119,7 @@ bool AdditionalHeader::Load(const char* file)
key.erase(0, strlen(ADD_HEAD_REGEX));
// compile
std::unique_ptr<regex_t> preg(new regex_t);
RegexPtr preg(new regex_t, regfree);
int result;
if(0 != (result = regcomp(preg.get(), key.c_str(), REG_EXTENDED | REG_NOSUB))){ // we do not need matching info
char errbuf[256];
@ -131,7 +131,7 @@ bool AdditionalHeader::Load(const char* file)
addheadlist.emplace_back(std::move(preg), key, head, value);
}else{
// not regex, directly comparing
addheadlist.emplace_back(nullptr, key, head, value);
addheadlist.emplace_back(RegexPtr(nullptr, regfree), key, head, value);
}
// set flag

View File

@ -30,25 +30,22 @@
//----------------------------------------------
// Structure / Typedef
//----------------------------------------------
typedef std::unique_ptr<regex_t, decltype(&regfree)> RegexPtr;
struct add_header{
add_header(std::unique_ptr<regex_t> pregex, std::string basestring, std::string headkey, std::string headvalue)
add_header(RegexPtr pregex, std::string basestring, std::string headkey, std::string headvalue)
: pregex(std::move(pregex))
, basestring(std::move(basestring))
, headkey(std::move(headkey))
, headvalue(std::move(headvalue))
{}
~add_header() {
if(pregex){
regfree(pregex.get());
}
}
add_header(const add_header&) = delete;
add_header(add_header&& val) = default;
add_header& operator=(const add_header&) = delete;
add_header& operator=(add_header&&) = delete;
std::unique_ptr<regex_t> pregex; // not nullptr means using regex, nullptr means comparing suffix directly.
RegexPtr pregex; // not nullptr means using regex, nullptr means comparing suffix directly.
std::string basestring;
std::string headkey;
std::string headvalue;