From 32ee93ef7399529cc9a97557ded0fb497f2f3670 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 20 Jan 2020 15:43:14 +0100 Subject: [PATCH] fix(runtime-c-api) `wasmer_instance_context_data_set` does nothing if `instance` is null. --- lib/runtime-c-api/src/instance.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index cf97452e3..e203093a8 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -428,8 +428,13 @@ pub extern "C" fn wasmer_instance_context_data_set( instance: *mut wasmer_instance_t, data_ptr: *mut c_void, ) { - let instance_ref = unsafe { &mut *(instance as *mut Instance) }; - instance_ref.context_mut().data = data_ptr; + if instance.is_null() { + return; + } + + let instance = unsafe { &mut *(instance as *mut Instance) }; + + instance.context_mut().data = data_ptr; } /// Gets the memory within the context at the index `memory_idx`.