Don't leak memory.

This commit is contained in:
Relintai 2021-11-18 12:07:28 +01:00
parent c23afa0332
commit 7ce989d12b
2 changed files with 21 additions and 10 deletions

View File

@ -230,6 +230,13 @@ HTMLParserTag::HTMLParserTag() {
}
HTMLParserTag::~HTMLParserTag() {
for (int i = 0; i < tags.size(); ++i) {
delete tags[i];
}
for (int i = 0; i < attributes.size(); ++i) {
delete attributes[i];
}
}
void HTMLParser::parse(const String &data) {
@ -244,7 +251,6 @@ void HTMLParser::parse(const String &data) {
t->data = data.substr(i, j - i + 1);
t->process();
t->print();
tags.push_back(t);
@ -270,25 +276,30 @@ void HTMLParser::parse(const String &data) {
}
//process tags into hierarchical order
//Vector<HTMLParserTag> tag_stack;
//for (int i = 0; i < tags.size(); ++i) {
//}
Vector<HTMLParserTag *> tag_stack;
for (int i = 0; i < tags.size(); ++i) {
delete tags[i];
}
}
String HTMLParser::to_string() {
return html->to_string();
if (!root) {
return "";
}
return root->to_string();
}
void HTMLParser::print() {
html->print();
if (root) {
root->print();
}
}
HTMLParser::HTMLParser() {
html = nullptr;
root = nullptr;
}
HTMLParser::~HTMLParser() {
if (root) {
delete root;
}
}

View File

@ -49,7 +49,7 @@ public:
class HTMLParser {
public:
HTMLParserTag *html;
HTMLParserTag *root;
void parse(const String &data);
//void parse_tag(const String &data, const int index);