Repository navigation
free the buffer maybe_pop_list allocates for bytes - #262
Merged
Merged
Conversation
`maybe_pop_list` copies a `bytes` value into a buffer from `alloc::alloc` and returns it, and wit-dylib lowers the list straight from that buffer. wit-dylib only frees lists it lowers element by element, so this buffer belongs to the interpreter, which never freed it: every `bytes` value a component passed to an import as a `list<u8>` stayed allocated for the life of the instance. Register the buffer with `defer_deallocate`, like the runtime's other temporary buffers, so it's freed when the `MyCall` drops. A pending async import keeps its `MyCall` until the subtask finishes, and an export keeps its `MyCall` until post-return. Fixes bytecodealliance#261.
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.
Fixes #261.
maybe_pop_listcopies abytesvalue into a buffer fromalloc::alloc, and wit-dylib lowers the list straight from that buffer without freeing it. So everybytesvalue a component passes to an import as alist<u8>stays allocated for the life of the instance.This registers the buffer with
defer_deallocate, like the runtime's other temporary buffers, so it's freed when theMyCalldrops. A pending async import keeps itsMyCallinPromise::ImportCalluntil the subtask finishes, and an export keeps itsMyCalluntil post-return, so the buffer isn't freed while it can still be read.Testing
The reproduction from #261 on Linux (
ubuntu-latest, Wasmtime CLI 48.0.2). Both wheels were built withmaturin build --release --features pyo3at v0.25.1, one with this change applied (3c50de8, the same diff on v0.25.1):bindingsbindingsos-write, bothOn this branch,
bash .github/workflows/lint.shpasses, and so doesCOMPONENTIZE_PY_TEST_COUNT=20 PROPTEST_MAX_SHRINK_ITERS=0 cargo test --release(127, 22 and 11 tests). Both ran in this workflow run.I haven't added a regression test, since the existing tests don't watch an instance's memory. I'm happy to add one if you have a place in mind.
This doesn't add the null check for a failed
alloc::allocthat #261 also describes. That's a separate change.