Skip to content
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 drop order for Module fields #2806

Merged
merged 2 commits into from Feb 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/api/src/sys/module.rs
Expand Up @@ -34,8 +34,22 @@ pub enum IoCompileError {
/// contents rather than a deep copy.
#[derive(Clone, MemoryUsage)]
pub struct Module {
store: Store,
// The field ordering here is actually significant because of the drop
// order: we want to drop the artifact before dropping the engine.
//
// The reason for this is that dropping the Artifact will de-register the
// trap handling metadata from the global registry. This must be done before
// the code memory for the artifact is freed (which happens when the store
// is dropped) since there is a chance that this memory could be reused by
// another module which will try to register its own trap information.
//
// Note that in Rust, the drop order for struct fields is from top to
// bottom: the opposite of C++.
//
// In the future, this code should be refactored to properly describe the
// ownership of the code and its metadata.
artifact: Arc<dyn Artifact>,
store: Store,
}

impl Module {
Expand Down