Skip to content

Commit 08d9578

Browse files
authored
Keep the Store alive until its StoreContext is no longer used. (#206)
As noted in #200, this is required as otherwise it could theoretically happen that the `Store` handle is deleted (with `wasmtime_store_delete`) in the GC finalizer thread even when at the same time a native call using the `StoreContext` handle is still executing in another thread, in case the `Store` object is no longer reachable. For native methods taking a handle parameter that is passed as `SafeHandle`, this is not required as the `SafeHandle` is already kept alive during the call. An exception is if you use `SafeHandle.DangerousGetHandle()` to retrieve the handle as pointer value and pass it; in that case you must also keep the `SafeHandle` alive. This commit also fixes an instance of the above noted issue in `Engine.IncrementEpoch()`, where `wasmtime_engine_increment_epoch` was declared as taking an `IntPtr` handle, and `Engine.IncrementEpoch()` used `SafeHandle.DangerousGetHandle()` without keeping the SafeHandle alive (this appears to have been introduced with #118).
1 parent b890e08 commit 08d9578

File tree

10 files changed

+371
-12
lines changed

10 files changed

+371
-12
lines changed

src/Engine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Dispose()
4141
/// </summary>
4242
public void IncrementEpoch()
4343
{
44-
Native.wasmtime_engine_increment_epoch(handle.DangerousGetHandle());
44+
Native.wasmtime_engine_increment_epoch(handle);
4545
}
4646

4747
internal Handle NativeHandle
@@ -84,7 +84,7 @@ private static class Native
8484
public static extern void wasm_engine_delete(IntPtr engine);
8585

8686
[DllImport(LibraryName)]
87-
public static extern void wasmtime_engine_increment_epoch(IntPtr engine);
87+
public static extern void wasmtime_engine_increment_epoch(Handle engine);
8888
}
8989

9090
private readonly Handle handle;

0 commit comments

Comments
 (0)