Commit c74a295
committed
Use pcre_free_study() to free PCRE JIT data
Function msc_pcre_cleanup(), which is responsible for freeing
compiled regex data, used either regular free() or pcre_free()
(depending on compilation settings) to free pcre_extra structure
(pointer to which is stored in regex->pe) created by pcre_study().
This was incorrect, structure returned by pcre_study() should be
freed by function pcre_free_study(). In case PCRE JIT is used,
pcre_study() makes some additional allocations itself (at least
for JITed executable code), which function pcre_free_study() frees.
If pcre_free_study() is not used a memory leak occurs because,
while pcre_extra structure itself might be freed by regular
free(), some additional data referenced by it is not.
Fix that by calling pcre_free_study() (instead of
free()/pcre_free()) on pointer returned by pcre_study().
Note that code creating msc_regex_t may allocate regex->pe with
malloc() or pcre_malloc() instead of pcre_study(). This case is
checked by testing if PCRE_EXTRA_EXECUTABLE_JIT flag on
regex->pe->flags is set. msc_pregcomp_ex() does not set that flag
itself (and it memsets the whole structure with zeros after
allocation) and pcre_free_study() actually does the same (it tests
for PCRE_EXTRA_EXECUTABLE_JIT flag, and, if that is zero, calls
pcre_free() on passed pointer).
Fixes #6101 parent f732fc6 commit c74a295
1 file changed
+6
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | | - | |
| 28 | + | |
26 | 29 | | |
27 | | - | |
| 30 | + | |
28 | 31 | | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
0 commit comments