Skip to content

Commit 08b5353

Browse files
author
Liu Dongmiao
committed
fix memory patch, part 2
1 parent 0dc5fdf commit 08b5353

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

Diff for: src/parser/driver.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ int Driver::parse(const std::string &f, const std::string &ref) {
129129
m_lastRule = nullptr;
130130
loc.push_back(new yy::location());
131131
if (ref.empty()) {
132-
loc.back()->begin.filename = loc.back()->end.filename = new std::string("<<reference missing or not informed>>");
132+
loc.back()->begin.filename = loc.back()->end.filename = std::make_shared<const std::string>("<<reference missing or not informed>>");
133133
} else {
134-
loc.back()->begin.filename = loc.back()->end.filename = new std::string(ref);
134+
loc.back()->begin.filename = loc.back()->end.filename = std::make_shared<const std::string>(ref);
135135
}
136136

137137
if (f.empty()) {

Diff for: src/parser/location.hh

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace yy {
8080
counter_type l = 1,
8181
counter_type c = 1)
8282
{
83-
filename = fn;
83+
filename = std::shared_ptr<filename_type>(fn);
8484
line = l;
8585
column = c;
8686
}
@@ -105,7 +105,7 @@ namespace yy {
105105
/** \} */
106106

107107
/// File name to which this position refers.
108-
filename_type* filename;
108+
std::shared_ptr<filename_type> filename;
109109
/// Current line number.
110110
counter_type line;
111111
/// Current column number.

Diff for: src/parser/seclang-parser.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ namespace yy {
13211321
#line 319 "seclang-parser.yy"
13221322
{
13231323
// Initialize the initial location.
1324-
yyla.location.begin.filename = yyla.location.end.filename = new std::string(driver.file);
1324+
yyla.location.begin.filename = yyla.location.end.filename = std::make_shared<const std::string>(driver.file);
13251325
}
13261326

13271327
#line 1328 "seclang-parser.cc"
@@ -2287,7 +2287,7 @@ namespace yy {
22872287
#line 1076 "seclang-parser.yy"
22882288
{
22892289
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
2290-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
2290+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
22912291
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
22922292
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
22932293
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -2305,7 +2305,7 @@ namespace yy {
23052305
/* op */ op,
23062306
/* variables */ v,
23072307
/* actions */ a,
2308-
/* transformations */ t,
2308+
/* transformations */ t.get(),
23092309
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[3].location.end.filename)),
23102310
/* line number */ yystack_[3].location.end.line
23112311
));
@@ -2344,7 +2344,7 @@ namespace yy {
23442344
#line 1125 "seclang-parser.yy"
23452345
{
23462346
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
2347-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
2347+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
23482348
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
23492349
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
23502350
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -2354,7 +2354,7 @@ namespace yy {
23542354
}
23552355
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
23562356
/* actions */ a,
2357-
/* transformations */ t,
2357+
/* transformations */ t.get(),
23582358
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
23592359
/* line number */ yystack_[1].location.end.line
23602360
));
@@ -2368,7 +2368,7 @@ namespace yy {
23682368
{
23692369
std::string err;
23702370
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
2371-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
2371+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
23722372
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
23732373
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
23742374
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -2379,7 +2379,7 @@ namespace yy {
23792379
std::unique_ptr<RuleScript> r(new RuleScript(
23802380
/* path to script */ yystack_[1].value.as < std::string > (),
23812381
/* actions */ a,
2382-
/* transformations */ t,
2382+
/* transformations */ t.get(),
23832383
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
23842384
/* line number */ yystack_[1].location.end.line
23852385
));

Diff for: src/parser/seclang-parser.yy

+7-7
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ using namespace modsecurity::operators;
318318
%initial-action
319319
{
320320
// Initialize the initial location.
321-
@$.begin.filename = @$.end.filename = new std::string(driver.file);
321+
@$.begin.filename = @$.end.filename = std::make_shared<const std::string>(driver.file);
322322
};
323323
%define parse.trace
324324
%define parse.error verbose
@@ -1075,7 +1075,7 @@ expression:
10751075
| DIRECTIVE variables op actions
10761076
{
10771077
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1078-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1078+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
10791079
for (auto &i : *$4.get()) {
10801080
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
10811081
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1093,7 +1093,7 @@ expression:
10931093
/* op */ op,
10941094
/* variables */ v,
10951095
/* actions */ a,
1096-
/* transformations */ t,
1096+
/* transformations */ t.get(),
10971097
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
10981098
/* line number */ @1.end.line
10991099
));
@@ -1124,7 +1124,7 @@ expression:
11241124
| CONFIG_DIR_SEC_ACTION actions
11251125
{
11261126
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1127-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1127+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
11281128
for (auto &i : *$2.get()) {
11291129
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
11301130
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1134,7 +1134,7 @@ expression:
11341134
}
11351135
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
11361136
/* actions */ a,
1137-
/* transformations */ t,
1137+
/* transformations */ t.get(),
11381138
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
11391139
/* line number */ @1.end.line
11401140
));
@@ -1144,7 +1144,7 @@ expression:
11441144
{
11451145
std::string err;
11461146
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1147-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1147+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
11481148
for (auto &i : *$2.get()) {
11491149
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
11501150
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1155,7 +1155,7 @@ expression:
11551155
std::unique_ptr<RuleScript> r(new RuleScript(
11561156
/* path to script */ $1,
11571157
/* actions */ a,
1158-
/* transformations */ t,
1158+
/* transformations */ t.get(),
11591159
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
11601160
/* line number */ @1.end.line
11611161
));

Diff for: src/parser/seclang-scanner.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -8526,7 +8526,7 @@ YY_RULE_SETUP
85268526
std::string err;
85278527
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
85288528
driver.loc.push_back(new yy::location());
8529-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
8529+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
85308530
yyin = fopen(f.c_str(), "r" );
85318531
if (!yyin) {
85328532
BEGIN(INITIAL);
@@ -8557,7 +8557,7 @@ YY_RULE_SETUP
85578557
for (auto& s: files) {
85588558
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
85598559
driver.loc.push_back(new yy::location());
8560-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
8560+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
85618561

85628562
yyin = fopen(f.c_str(), "r" );
85638563
if (!yyin) {
@@ -8590,7 +8590,7 @@ YY_RULE_SETUP
85908590
c.setKey(key);
85918591

85928592
driver.loc.push_back(new yy::location());
8593-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
8593+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
85948594
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
85958595
yypush_buffer_state(temp);
85968596

Diff for: src/parser/seclang-scanner.ll

+3-3
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ EQUALS_MINUS (?i:=\-)
12531253
std::string err;
12541254
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
12551255
driver.loc.push_back(new yy::location());
1256-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
1256+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
12571257
yyin = fopen(f.c_str(), "r" );
12581258
if (!yyin) {
12591259
BEGIN(INITIAL);
@@ -1281,7 +1281,7 @@ EQUALS_MINUS (?i:=\-)
12811281
for (auto& s: files) {
12821282
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
12831283
driver.loc.push_back(new yy::location());
1284-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
1284+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
12851285
12861286
yyin = fopen(f.c_str(), "r" );
12871287
if (!yyin) {
@@ -1310,7 +1310,7 @@ EQUALS_MINUS (?i:=\-)
13101310
c.setKey(key);
13111311
13121312
driver.loc.push_back(new yy::location());
1313-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
1313+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
13141314
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
13151315
yypush_buffer_state(temp);
13161316

0 commit comments

Comments
 (0)