Fix memleak in regression.cc

This commit is contained in:
Ervin Hegedus 2024-03-27 11:45:05 +01:00
parent 625f9a5300
commit 39848e5564
No known key found for this signature in database
GPG Key ID: 5FA5BC3F5EC41F61

View File

@ -476,7 +476,9 @@ int main(int argc, char **argv) {
std::string ver(MODSECURITY_VERSION); std::string ver(MODSECURITY_VERSION);
std::string envvar("MODSECURITY=ModSecurity " + ver + " regression tests"); std::string envvar("MODSECURITY=ModSecurity " + ver + " regression tests");
putenv(strdup(envvar.c_str())); char *envvarptr = strdup(envvar.c_str());
putenv(envvarptr);
#ifndef NO_LOGS #ifndef NO_LOGS
int test_number = 0; int test_number = 0;
#endif #endif
@ -536,6 +538,9 @@ int main(int argc, char **argv) {
if (test.m_count_all) { if (test.m_count_all) {
std::cout << std::to_string(keyList.size()) << std::endl; std::cout << std::to_string(keyList.size()) << std::endl;
if (envvarptr != nullptr) {
free(envvarptr);
}
exit(0); exit(0);
} }
@ -606,5 +611,9 @@ int main(int argc, char **argv) {
} }
#endif #endif
if (envvarptr != nullptr) {
free(envvarptr);
}
return 0; return 0;
} }