Skip to content

Memory leak if builded modsecurity with --enable-pcre-study #610

Closed
@weliu

Description

@weliu

In apache2/msc_pcre.c line 68-74, we will get regex->pe from pcre_study() if we compile with --enable-pcre-study.

#ifdef WITH_PCRE_STUDY
#ifdef WITH_PCRE_JIT
pe = pcre_study(regex->re, PCRE_STUDY_JIT_COMPILE, &errptr);
#else
pe = pcre_study(regex->re, 0, &errptr);
#endif
#endif

However we will use pcre_free() or free() to free it in msc_pcre_cleanup(), the right choice here is pcre_free_study().
if (regex->pe != NULL) {

if defined(VERSION_NGINX)

        pcre_free(regex->pe);

else

        free(regex->pe);

endif

        regex->pe = NULL;
    }

This will lead to memory leak, the memory that leaked was allocated use SLJIT_MALLOC in pcre_study().

This can be a big problem if we use Apache graceful restart.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions