Skip to content

Commit 0e8290a

Browse files
author
Liu Dongmiao
committed
fix memory patch, part 2
1 parent d7c77a7 commit 0e8290a

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

src/parser/driver.cc

Lines changed: 2 additions & 2 deletions
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()) {

src/parser/location.hh

Lines changed: 2 additions & 2 deletions
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.

src/parser/seclang-parser.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ namespace yy {
13211321
#line 320 "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 1078 "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 1127 "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
));

src/parser/seclang-parser.yy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ using namespace modsecurity::operators;
319319
%initial-action
320320
{
321321
// Initialize the initial location.
322-
@$.begin.filename = @$.end.filename = new std::string(driver.file);
322+
@$.begin.filename = @$.end.filename = std::make_shared<const std::string>(driver.file);
323323
};
324324
%define parse.trace
325325
%define parse.error verbose
@@ -1077,7 +1077,7 @@ expression:
10771077
| DIRECTIVE variables op actions
10781078
{
10791079
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1080-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1080+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
10811081
for (auto &i : *$4.get()) {
10821082
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
10831083
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1095,7 +1095,7 @@ expression:
10951095
/* op */ op,
10961096
/* variables */ v,
10971097
/* actions */ a,
1098-
/* transformations */ t,
1098+
/* transformations */ t.get(),
10991099
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
11001100
/* line number */ @1.end.line
11011101
));
@@ -1126,7 +1126,7 @@ expression:
11261126
| CONFIG_DIR_SEC_ACTION actions
11271127
{
11281128
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1129-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1129+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
11301130
for (auto &i : *$2.get()) {
11311131
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
11321132
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1136,7 +1136,7 @@ expression:
11361136
}
11371137
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
11381138
/* actions */ a,
1139-
/* transformations */ t,
1139+
/* transformations */ t.get(),
11401140
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
11411141
/* line number */ @1.end.line
11421142
));
@@ -1146,7 +1146,7 @@ expression:
11461146
{
11471147
std::string err;
11481148
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
1149-
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
1149+
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
11501150
for (auto &i : *$2.get()) {
11511151
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
11521152
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
@@ -1157,7 +1157,7 @@ expression:
11571157
std::unique_ptr<RuleScript> r(new RuleScript(
11581158
/* path to script */ $1,
11591159
/* actions */ a,
1160-
/* transformations */ t,
1160+
/* transformations */ t.get(),
11611161
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
11621162
/* line number */ @1.end.line
11631163
));

src/parser/seclang-scanner.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8544,7 +8544,7 @@ YY_RULE_SETUP
85448544
std::string err;
85458545
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
85468546
driver.loc.push_back(new yy::location());
8547-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
8547+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
85488548
yyin = fopen(f.c_str(), "r" );
85498549
if (!yyin) {
85508550
BEGIN(INITIAL);
@@ -8575,7 +8575,7 @@ YY_RULE_SETUP
85758575
for (auto& s: files) {
85768576
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
85778577
driver.loc.push_back(new yy::location());
8578-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
8578+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
85798579

85808580
yyin = fopen(f.c_str(), "r" );
85818581
if (!yyin) {
@@ -8608,7 +8608,7 @@ YY_RULE_SETUP
86088608
c.setKey(key);
86098609

86108610
driver.loc.push_back(new yy::location());
8611-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
8611+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
86128612
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
86138613
yypush_buffer_state(temp);
86148614

src/parser/seclang-scanner.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ EQUALS_MINUS (?i:=\-)
12571257
std::string err;
12581258
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
12591259
driver.loc.push_back(new yy::location());
1260-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
1260+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
12611261
yyin = fopen(f.c_str(), "r" );
12621262
if (!yyin) {
12631263
BEGIN(INITIAL);
@@ -1285,7 +1285,7 @@ EQUALS_MINUS (?i:=\-)
12851285
for (auto& s: files) {
12861286
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
12871287
driver.loc.push_back(new yy::location());
1288-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
1288+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
12891289
12901290
yyin = fopen(f.c_str(), "r" );
12911291
if (!yyin) {
@@ -1314,7 +1314,7 @@ EQUALS_MINUS (?i:=\-)
13141314
c.setKey(key);
13151315
13161316
driver.loc.push_back(new yy::location());
1317-
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
1317+
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
13181318
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
13191319
yypush_buffer_state(temp);
13201320

0 commit comments

Comments
 (0)