mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +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;
|
||||
|
||||
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
|
||||
int test_number = 0;
|
||||
#endif
|
||||
|
@ -36,9 +36,8 @@ void print_help(const char *name) {
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
modsecurity::RulesSet *rules;
|
||||
auto rules = std::make_unique<modsecurity::RulesSet>();
|
||||
char **args = argv;
|
||||
rules = new modsecurity::RulesSet();
|
||||
int ret = 0;
|
||||
|
||||
args++;
|
||||
@ -50,41 +49,26 @@ int main(int argc, char **argv) {
|
||||
|
||||
while (*args != NULL) {
|
||||
struct stat buffer;
|
||||
std::string argFull("");
|
||||
const char *arg = *args;
|
||||
std::string arg = *args;
|
||||
std::string err;
|
||||
int r;
|
||||
|
||||
if (argFull.empty() == false) {
|
||||
if (arg[strlen(arg)-1] == '\"') {
|
||||
argFull.append(arg, strlen(arg)-1);
|
||||
goto next;
|
||||
} else {
|
||||
argFull.append(arg);
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
// strip arg from leading and trailing '"' chars
|
||||
arg.erase(arg.find_last_not_of('\"')+1);
|
||||
arg.erase(0, arg.find_first_not_of('\"'));
|
||||
|
||||
if (arg[0] == '\"' && argFull.empty() == true) {
|
||||
if (arg[strlen(arg)-1] == '\"') {
|
||||
argFull.append(arg+1, strlen(arg) - 2);
|
||||
} else {
|
||||
argFull.append(arg+1);
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
|
||||
if (argFull.empty() == false) {
|
||||
arg = strdup(argFull.c_str());
|
||||
argFull.clear();
|
||||
if (arg.empty() == true) {
|
||||
args++;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << " : " << arg << " -- ";
|
||||
if (stat(arg, &buffer) == 0) {
|
||||
r = rules->loadFromUri(arg);
|
||||
if (stat(arg.c_str(), &buffer) == 0) {
|
||||
r = rules->loadFromUri(arg.c_str());
|
||||
} else {
|
||||
r = rules->load(arg);
|
||||
r = rules->load(arg.c_str());
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
err.assign(rules->m_parserError.str());
|
||||
rules->m_parserError.str("");
|
||||
@ -95,12 +79,10 @@ int main(int argc, char **argv) {
|
||||
if (err.empty() == false) {
|
||||
std::cerr << " " << err << std::endl;
|
||||
}
|
||||
next:
|
||||
|
||||
args++;
|
||||
}
|
||||
|
||||
delete rules;
|
||||
|
||||
if (ret < 0) {
|
||||
std::cout << "Test failed." << std::endl;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user