Skip to content

Commit

Permalink
Plug a memory leak in tre_match().
Browse files Browse the repository at this point in the history
When not using `alloca()`, we need to free `tags` before returning.

Obtained from the R repository.
  • Loading branch information
dag-erling committed Jul 30, 2024
1 parent 1cff35b commit 6f09108
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ tre_match(const tre_tnfa_t *tnfa, const void *string, size_t len,
if (source->rewind == NULL || source->compare == NULL)
/* The backtracking matcher requires rewind and compare
capabilities from the input stream. */
#ifndef TRE_USE_ALLOCA
if (tags)
xfree(tags);
#endif /* !TRE_USE_ALLOCA */
return REG_BADPAT;
}
status = tre_tnfa_run_backtrack(tnfa, string, (int)len, type,
Expand Down

0 comments on commit 6f09108

Please sign in to comment.