ModSecurity icon indicating copy to clipboard operation
ModSecurity copied to clipboard

Memory leak in msc_pregcomp_ex

Open marcstern opened this issue 5 years ago • 2 comments

apr_pool_cleanup_register() is called at the very end of the function. In case any problem occurs (e.g., regex cannot compile) we return immediately, so the cleanup is never performed.

apr_pool_cleanup_register() should be called right after calling pcre_compile() to cleanup memory allocated by pcre.

marcstern avatar Sep 22 '20 18:09 marcstern

@marcstern Please mention the code part here.

Usually when a regex is not compiled ModSecurity failed to start, the process die and the kernel will free-up the memory resources. Whats leads you to believe that this is an issue?

zimmerle avatar Sep 23 '20 12:09 zimmerle

There's one case where we return before cleaning up. It's in case of a memory allocation problem, so it should hopefully not happen often. However, in the case we add another test in the middle (and we should probably add one with the fix https://github.com/SpiderLabs/ModSecurity/issues/610), we'll introduce a memory leak.

marcstern avatar Sep 24 '20 11:09 marcstern