Repository navigation
Free the RE2 object of a pattern Compile refuses - #293
Closed
nitzan-b-sp wants to merge 1 commit into
Closed
nitzan-b-sp wants to merge 1 commit into
nitzan-b-sp wants to merge 1 commit into
Conversation
Compile returned the parse error without deleting the RE2 object, so every refused pattern stayed in the module's memory. Refs wasilibs#292.
This file contains hidden or 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
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.Suggestion cannot be applied right now. Please check back later.
Refs #292
Problem
Compilecreates the RE2 object, reads its error code, and on a refused pattern returns the error without deletingthe object. Nothing else holds the pointer, so each refusal stays in the module's memory for the life of the process.
A program compiling patterns it doesn't control grows with every invalid one: 100,000 compiles of
(abcadd about19 MB per round, and a 1 KB unclosed group about 3 KB per compile. The issue has the repro and the numbers.
Change
internal/re2.go: delete the RE2 object as soon as its error has been read.reErrorcopies the error argument intoa Go string first, so the message is unaffected.
deleteREexists in both the wasm2go and there2_cgobuilds, sothe fix covers both.
internal/re2_wasm2go_compile_test.go: compiles a refused 4 KB pattern 2,000 times and checks the module's memorydoesn't grow. It fails without the change (the memory grows from 0.3 MB to 25 MB) and passes with it. It is wasm2go only,
since that is where the memory can be read.
Testing
go run ./build test: passes.go run ./build lint-go: 0 issues.Patterns that compile behave as before.
The two other points in #292 (a memory budget for
Compile, and turning off RE2's error logging in the wasm2go build)are not in this PR. I'm happy to send them separately if you want them.