bryancall commented on code in PR #12465:
URL: https://github.com/apache/trafficserver/pull/12465#discussion_r2299139748
##########
src/tsutil/Regex.cc:
##########
@@ -126,8 +126,7 @@ struct RegexMatches::_MatchData {
//----------------------------------------------------------------------------
RegexMatches::RegexMatches(uint32_t size)
{
- pcre2_general_context *ctx =
- pcre2_general_context_create(&RegexMatches::malloc, [](void *, void *) ->
void {}, static_cast<void *>(this));
+ pcre2_general_context *ctx =
pcre2_general_context_create(&RegexMatches::malloc, &RegexMatches::free,
static_cast<void *>(this));
pcre2_match_data *match_data = pcre2_match_data_create(size, ctx);
Review Comment:
With the original code `RegexMatches::malloc()` would return nullptr if
there is no space in the buffer and it will fall back to malloc and free in the
`pcre2_match_data_create()` call below. I didn't call `free()` if the buffer
had enough space already, the no-op free above.
There is a unit test that covers the case where we run out of buffer space.
If you would rather do your approach with checking the pointer to see if it
needs to be freed then you should also remove the code below that checks to see
if there is a nullptr and falling back to `malloc()` and `free()`.
Maybe just adding better comments to the original code so people know how
the fallback to malloc and free works.
--
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]