Skip to content

Commit

Permalink
another memory leak patch
Browse files Browse the repository at this point in the history
  • Loading branch information
krangelov committed Jan 10, 2024
1 parent 0078be8 commit bbbdb70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/runtime/c/pgf/parser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ PgfParser::PgfParser(ref<PgfConcr> concr, ref<PgfConcrLincat> start, PgfText *se
this->before->nodes.push_back(node);
}

void PgfParser::shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, Production *prod,
bool PgfParser::shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, Production *prod,
Stage *before, Stage *after)
{
ref<Vector<PgfLRShift>> shifts = vector_elem(concr->lrtable,parent->state_id)->shifts;
Expand All @@ -1402,11 +1402,13 @@ void PgfParser::shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, P
after->nodes.push_back(node);
}

bool added = false;
if (std::find(node->choice->prods.begin(), node->choice->prods.end(), prod) == node->choice->prods.end()) {
node->choice->prods.push_back(prod);
#ifdef DEBUG_PARSER
print_prod(node->choice, prod);
#endif
added = true;
}

if (std::find(node->parents.begin(), node->parents.end(), parent) == node->parents.end()) {
Expand All @@ -1416,9 +1418,11 @@ void PgfParser::shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, P
#endif
}

break;
return added;
}
}

return false;
}

void PgfParser::shift(StackNode *parent, Stage *before)
Expand Down Expand Up @@ -1695,10 +1699,11 @@ void PgfParser::match(ref<PgfConcrLin> lin, size_t seq_index, PgfExn* err)
size_t index = seq_index / lin->lincat->fields->len;
size_t r = seq_index % lin->lincat->fields->len;

Production *prod = new(lin,index) Production();

for (StackNode *parent : before->nodes) {
shift(parent, lin->lincat, r, prod, before, after);
Production *prod = new(lin,index) Production();
if (!shift(parent, lin->lincat, r, prod, before, after)) {
delete prod;
}
}
}

Expand Down Expand Up @@ -1897,7 +1902,6 @@ PgfParser::~PgfParser()
u->free_ref(expr);
}

std::priority_queue<ExprState*, std::vector<ExprState*>, CompareExprState> queue;
while (!queue.empty()) {
ExprState *state = queue.top(); queue.pop();
delete state;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/c/pgf/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class PGF_INTERNAL_DECL PgfParser : public PgfPhraseScanner, public PgfExprEnum
Choice *top_choice;
size_t top_choice_index;

void shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, Production *prod,
bool shift(StackNode *parent, ref<PgfConcrLincat> lincat, size_t r, Production *prod,
Stage *before, Stage *after);
void shift(StackNode *parent, Stage *before);
void shift(StackNode *parent, Stage *before, Stage *after);
Expand Down Expand Up @@ -156,7 +156,7 @@ class PGF_INTERNAL_DECL PgfParser : public PgfPhraseScanner, public PgfExprEnum

public:
PgfParser(ref<PgfConcr> concr, ref<PgfConcrLincat> start, PgfText *sentence, bool case_sensitive, PgfMarshaller *m, PgfUnmarshaller *u);
~PgfParser();
virtual ~PgfParser();

virtual void space(PgfTextSpot *start, PgfTextSpot *end, PgfExn* err);
virtual void start_matches(PgfTextSpot *end, PgfExn* err);
Expand Down

0 comments on commit bbbdb70

Please sign in to comment.