Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/koinos/vm_manager/fizzy/fizzy_vm_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ void fizzy_runner::instantiate_module()
uint32_t memory_pages_limit = 512; // Number of 64k pages allowed to allocate

KOINOS_ASSERT( _instance == nullptr, runner_state_exception, "_instance was unexpectedly non-null" );
_instance = fizzy_resolve_instantiate( _module->get(),

// fizzy_resolve_instantiate takes ownership of the module it is given and
// frees it via fizzy_free_instance. The module here is owned by the cache's
// module_guard (which frees it via fizzy_free_module), so instantiate a clone
// instead — otherwise the same FizzyModule is freed twice (double-free).
_instance = fizzy_resolve_instantiate( fizzy_clone_module( _module->get() ),
host_funcs,
num_host_funcs,
nullptr,
Expand Down
6 changes: 6 additions & 0 deletions src/koinos/vm_manager/fizzy/module_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class module_guard
_module( m )
{}

// Sole owner of the raw FizzyModule; copying would free it twice.
module_guard( const module_guard& ) = delete;
module_guard& operator=( const module_guard& ) = delete;
module_guard( module_guard&& ) = delete;
module_guard& operator=( module_guard&& ) = delete;

~module_guard()
{
fizzy_free_module( _module );
Expand Down
Loading