jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

Fix memory leak when using continue or break statement with syntaxError

Open gergocs opened this issue 1 year ago • 9 comments

This patch fixes #5062.

JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]

gergocs avatar Dec 09 '24 09:12 gergocs

Does this patch increase memory consumption in the normal (no parse error) case?

zherczeg avatar Dec 09 '24 12:12 zherczeg

Yes it does. For example the regression-test-issue-1555.js test fails if the heap size is not increased.

gergocs avatar Dec 09 '24 12:12 gergocs

Would it be possible to free the memory at its regular place as well?

zherczeg avatar Dec 09 '24 12:12 zherczeg

I don't think so. I have debugging this issue a very long time and didn't find any better methods to keep track of possible non freed pointers.

gergocs avatar Dec 09 '24 12:12 gergocs

I mean when a pointer is not needed, it could be removed from the tracker and free it. I suspect we keep pointers too long around this way.

zherczeg avatar Dec 09 '24 13:12 zherczeg

https://github.com/jerryscript-project/jerryscript/blob/8d44eed661fc82324e178675937c88d9b1b34573/jerry-core/parser/js/js-parser.c#L3254

The parser already does a lot of cleanup on throw. If we could put this branch list into some local context (a chain list with a head), we could cleanup it without complex structures.

zherczeg avatar Dec 11 '24 08:12 zherczeg

Currently it is a chain list not a complex structure and stored in the context to easily pass around.

gergocs avatar Dec 11 '24 08:12 gergocs

Not the complexity, but it has while loops. The design is better if less scanning is needed.

Is it operating like a stack btw? So we usually remove items form the end?

zherczeg avatar Dec 11 '24 08:12 zherczeg

No, it's not like stack.

gergocs avatar Dec 11 '24 08:12 gergocs