Fix a memory leak in parseAsm()

This commit is contained in:
BigBahss 2021-02-16 05:24:10 -05:00 committed by huderlem
parent d9340d3b73
commit f65b6a047e

View file

@ -65,25 +65,19 @@ QList<QStringList>* ParseUtil::parseAsm(QString filename) {
text = readTextFile(root + "/" + filename); text = readTextFile(root + "/" + filename);
QStringList lines = text.split('\n'); QStringList lines = text.split('\n');
for (QString line : lines) { for (QString line : lines) {
QString label;
strip_comment(&line); strip_comment(&line);
if (line.trimmed().isEmpty()) { if (line.trimmed().isEmpty()) {
} else if (line.contains(':')) { } else if (line.contains(':')) {
label = line.left(line.indexOf(':')); QString label = line.left(line.indexOf(':'));
QStringList *list = new QStringList; QStringList list{ ".label", label }; // .label is not a real keyword. It's used only to make the output more regular.
list->append(".label"); // This is not a real keyword. It's used only to make the output more regular. parsed->append(list);
list->append(label);
parsed->append(*list);
// There should not be anything else on the line. // There should not be anything else on the line.
// gas will raise a syntax error if there is. // gas will raise a syntax error if there is.
} else { } else {
line = line.trimmed(); line = line.trimmed();
//parsed->append(line.split(QRegExp("\\s*,\\s*")));
QString macro;
QStringList params;
int index = line.indexOf(QRegExp("\\s+")); int index = line.indexOf(QRegExp("\\s+"));
macro = line.left(index); QString macro = line.left(index);
params = line.right(line.length() - index).trimmed().split(QRegExp("\\s*,\\s*")); QStringList params(line.right(line.length() - index).trimmed().split(QRegExp("\\s*,\\s*")));
params.prepend(macro); params.prepend(macro);
parsed->append(params); parsed->append(params);
} }