Mercurial > hg > orthanc
diff Core/HttpServer/StringMatcher.cpp @ 3403:630fc934597f
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Jun 2019 17:24:26 +0200 |
parents | 4acd1431e603 |
children | 8de071691d13 |
line wrap: on
line diff
--- 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_)); }