# HG changeset patch # User Sebastien Jodogne # Date 1559921066 -7200 # Node ID 630fc934597f82983a4d9ae37f05586726e131a1 # Parent cf31b5bacce3d863c1eb04736d2d3d28a7a1268e fix diff -r cf31b5bacce3 -r 630fc934597f Core/HttpServer/StringMatcher.cpp --- a/Core/HttpServer/StringMatcher.cpp Fri Jun 07 15:06:17 2019 +0200 +++ b/Core/HttpServer/StringMatcher.cpp Fri Jun 07 17:24:26 2019 +0200 @@ -51,6 +51,8 @@ Algorithm algorithm_; public: + // WARNING - The lifetime of "pattern_" must be larger than + // "search_", as the latter internally keeps a pointer to "pattern" (*) Search(const std::string& pattern) : algorithm_(pattern.begin(), pattern.end()) { @@ -69,10 +71,14 @@ StringMatcher::StringMatcher(const std::string& pattern) : - search_(new Search(pattern)), pattern_(pattern), valid_(false) { + // WARNING - Don't use "pattern" (local variable, will be + // destroyed once exiting the constructor) but "pattern_" + // (variable member, will last as long as the algorithm), + // otherwise lifetime is bad! (*) + search_.reset(new Search(pattern_)); } diff -r cf31b5bacce3 -r 630fc934597f Core/HttpServer/StringMatcher.h --- a/Core/HttpServer/StringMatcher.h Fri Jun 07 15:06:17 2019 +0200 +++ b/Core/HttpServer/StringMatcher.h Fri Jun 07 17:24:26 2019 +0200 @@ -48,8 +48,6 @@ private: class Search; - // WARNING - The lifetime of "pattern_" must be larger than - // "search_", as the latter references "pattern_" boost::shared_ptr search_; // PImpl pattern std::string pattern_; bool valid_;