mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 13:26:01 +03:00
Replaced the use of "new" in find_resource
- Addresses SonarCloud issue cpp:S5025 (Memory should not be managed manually) - This function was not changed for the Windows port, but a similar change to the one suggested was done in expandEnv in the same file. - The first stream is not destructed at the exact same point it was in the previous code (but rather when the second stream replaces it on assignment to the same variable). An arbitrary scope could have been introduced to destruct the object at the same place, but it doesn't seem to be necessary and would make the code a bit strange.
This commit is contained in:
parent
b69405a372
commit
a8e132f3a1
@ -98,19 +98,15 @@ double cpu_seconds(void) {
|
||||
|
||||
std::string find_resource(const std::string& resource,
|
||||
const std::string& config, std::string *err) {
|
||||
std::ifstream *iss;
|
||||
|
||||
err->assign("Looking at: ");
|
||||
// Trying absolute or relative to the current dir.
|
||||
iss = new std::ifstream(resource, std::ios::in);
|
||||
if (iss->is_open()) {
|
||||
iss->close();
|
||||
delete iss;
|
||||
auto iss = std::ifstream(resource, std::ios::in);
|
||||
if (iss.is_open()) {
|
||||
return resource;
|
||||
} else {
|
||||
err->append("'" + resource + "', ");
|
||||
}
|
||||
delete iss;
|
||||
|
||||
// What about `*' ?
|
||||
if (utils::expandEnv(resource, 0).size() > 0) {
|
||||
@ -121,15 +117,12 @@ std::string find_resource(const std::string& resource,
|
||||
|
||||
// Trying the same path of the configuration file.
|
||||
std::string f = get_path(config) + "/" + resource;
|
||||
iss = new std::ifstream(f, std::ios::in);
|
||||
if (iss->is_open()) {
|
||||
iss->close();
|
||||
delete iss;
|
||||
iss = std::ifstream(f, std::ios::in);
|
||||
if (iss.is_open()) {
|
||||
return f;
|
||||
} else {
|
||||
err->append("'" + f + "', ");
|
||||
}
|
||||
delete iss;
|
||||
|
||||
// What about `*' ?
|
||||
if (utils::expandEnv(f, 0).size() > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user