mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
Merge pull request #3114 from airween/v3/sonarmemleakfix
fix: Sonarcloud memleak fixes
This commit is contained in:
commit
a23e88f79f
@ -480,9 +480,14 @@ int main(int argc, char **argv) {
|
|||||||
ModSecurityTest<RegressionTest> test;
|
ModSecurityTest<RegressionTest> test;
|
||||||
|
|
||||||
std::string ver(MODSECURITY_VERSION);
|
std::string ver(MODSECURITY_VERSION);
|
||||||
std::string envvar("MODSECURITY=ModSecurity " + ver + " regression tests");
|
std::string envvar("ModSecurity " + ver + " regression tests");
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
setenv("MODSECURITY", envvar.c_str(), 1);
|
||||||
|
#else
|
||||||
|
_putenv_s("MODSECURITY", envvar.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
putenv(strdup(envvar.c_str()));
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
int test_number = 0;
|
int test_number = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,9 +36,8 @@ void print_help(const char *name) {
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
modsecurity::RulesSet *rules;
|
auto rules = std::make_unique<modsecurity::RulesSet>();
|
||||||
char **args = argv;
|
char **args = argv;
|
||||||
rules = new modsecurity::RulesSet();
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
args++;
|
args++;
|
||||||
@ -50,41 +49,26 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
while (*args != NULL) {
|
while (*args != NULL) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
std::string argFull("");
|
std::string arg = *args;
|
||||||
const char *arg = *args;
|
|
||||||
std::string err;
|
std::string err;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (argFull.empty() == false) {
|
// strip arg from leading and trailing '"' chars
|
||||||
if (arg[strlen(arg)-1] == '\"') {
|
arg.erase(arg.find_last_not_of('\"')+1);
|
||||||
argFull.append(arg, strlen(arg)-1);
|
arg.erase(0, arg.find_first_not_of('\"'));
|
||||||
goto next;
|
|
||||||
} else {
|
|
||||||
argFull.append(arg);
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg[0] == '\"' && argFull.empty() == true) {
|
if (arg.empty() == true) {
|
||||||
if (arg[strlen(arg)-1] == '\"') {
|
args++;
|
||||||
argFull.append(arg+1, strlen(arg) - 2);
|
continue;
|
||||||
} else {
|
|
||||||
argFull.append(arg+1);
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argFull.empty() == false) {
|
|
||||||
arg = strdup(argFull.c_str());
|
|
||||||
argFull.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << " : " << arg << " -- ";
|
std::cout << " : " << arg << " -- ";
|
||||||
if (stat(arg, &buffer) == 0) {
|
if (stat(arg.c_str(), &buffer) == 0) {
|
||||||
r = rules->loadFromUri(arg);
|
r = rules->loadFromUri(arg.c_str());
|
||||||
} else {
|
} else {
|
||||||
r = rules->load(arg);
|
r = rules->load(arg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
err.assign(rules->m_parserError.str());
|
err.assign(rules->m_parserError.str());
|
||||||
rules->m_parserError.str("");
|
rules->m_parserError.str("");
|
||||||
@ -95,12 +79,10 @@ int main(int argc, char **argv) {
|
|||||||
if (err.empty() == false) {
|
if (err.empty() == false) {
|
||||||
std::cerr << " " << err << std::endl;
|
std::cerr << " " << err << std::endl;
|
||||||
}
|
}
|
||||||
next:
|
|
||||||
args++;
|
args++;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete rules;
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
std::cout << "Test failed." << std::endl;
|
std::cout << "Test failed." << std::endl;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user