@@ -51,7 +51,7 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
51
51
for (const auto & token : tokens) {
52
52
if (! token.empty ()) {
53
53
54
- std::istream * iss;
54
+ std::unique_ptr<std:: istream> iss;
55
55
56
56
if (token.compare (0 , 8 , " https://" ) == 0 ) {
57
57
Utils::HttpsClient client;
@@ -60,26 +60,22 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
60
60
error->assign (client.error );
61
61
return false ;
62
62
}
63
- iss = new std::stringstream (client.content );
63
+ iss = std::make_unique<std:: stringstream> (client.content );
64
64
} else {
65
65
std::string err;
66
66
std::string resource = utils::find_resource (token, config, &err);
67
- iss = new std::ifstream (resource, std::ios::in);
68
-
69
- if (((std::ifstream *)iss)->is_open () == false ) {
67
+ auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
68
+ if (file->is_open () == false ) {
70
69
error->assign (" Failed to open file: '" + token + " '. " + err);
71
- delete iss;
72
70
return false ;
73
71
}
72
+ iss = std::move (file);
74
73
}
75
-
76
74
for (std::string line; std::getline (*iss, line); ) {
77
75
if (isComment (line) == false ) {
78
76
acmp_add_pattern (m_p, line.c_str (), NULL , NULL , line.length ());
79
77
}
80
78
}
81
-
82
- delete iss;
83
79
}
84
80
}
85
81
0 commit comments