New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #9588, 140a96b: [Squirrel] Reaching memory limit during script registration could prevent further script detections #9589
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ript registration could prevent further script detections Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
LordAro
approved these changes
Oct 2, 2021
TrueBrain
pushed a commit
to TrueBrain/OpenTTD
that referenced
this pull request
Oct 3, 2021
…ript registration could prevent further script detections (OpenTTD#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
TrueBrain
pushed a commit
to TrueBrain/OpenTTD
that referenced
this pull request
Oct 3, 2021
…ript registration could prevent further script detections (OpenTTD#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
TrueBrain
pushed a commit
to TrueBrain/OpenTTD
that referenced
this pull request
Oct 3, 2021
…ript registration could prevent further script detections (OpenTTD#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
TrueBrain
pushed a commit
to TrueBrain/OpenTTD
that referenced
this pull request
Oct 3, 2021
…ript registration could prevent further script detections (OpenTTD#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
TrueBrain
pushed a commit
to TrueBrain/OpenTTD
that referenced
this pull request
Oct 3, 2021
…ript registration could prevent further script detections (OpenTTD#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
TrueBrain
pushed a commit
that referenced
this pull request
Oct 3, 2021
…gistration could prevent further script detections (#9589) Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Motivation / Problem
When a script's
info.nut
triggersMaximum memory allocation exceeded
, it can prevent the detection of other scripts of the same type.This happens because the memory allocation triggering the limit is still accounted in the allocator for all other detections.
And that means this memory is also never freed.
Once the
allocated_size
issue was fixed, another issue appeared, a script failing to register due to memory limit would still be available ingame (and possibly other scripts that should have failed memory check). That's because scripts are scanned multiple times, and the error was not properly reset.Finally another memory leak exists, when the memory limit is triggered in a constructor and using placement new.
Regarding the reported crash, it's because
DummyAI
registration triggers the memory limit due to a previous failing script and incomplete cleaning between registrations.Description
Properly count allocated memory, and free memory not referenced by squirrel before it's lost.
I added an assert to ensure all allocated memory is managed by squirrel and its garbage collector, or is taken care of otherwise.
Limitations
As now the engine is properly reset, the failing scripts are now reported multiple times in debug console, because many rescan happen during startup.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.