Skip to content

Commit

Permalink
Merge pull request #33 from multiversx/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak for c-api clean functions
  • Loading branch information
ovstinga authored Oct 11, 2023
2 parents b88e4bc + 6b8b5d8 commit b464a6e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions c-api/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ vm_exec_result_t vm_check_signatures(vm_exec_instance_t *instance_ptr);
*
* C API function, works with raw object pointers.
*/
void vm_exec_executor_destroy(vm_exec_executor_t *executor);
void vm_exec_executor_destroy(vm_exec_executor_t *executor_ptr);

/**
* Sets the data that can be hold by an instance context.
Expand Down Expand Up @@ -380,7 +380,7 @@ vm_exec_result_t vm_exec_instance_call(vm_exec_instance_t *instance_ptr, const c
*
* C API function, works with raw object pointers.
*/
void vm_exec_instance_destroy(vm_exec_instance_t *instance);
void vm_exec_instance_destroy(vm_exec_instance_t *instance_ptr);

/**
* Creates a new VM executor instance from cache.
Expand Down
7 changes: 4 additions & 3 deletions c-api/src/capi_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ pub unsafe extern "C" fn vm_exec_executor_set_vm_hooks_ptr(
/// C API function, works with raw object pointers.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn vm_exec_executor_destroy(executor: *mut vm_exec_executor_t) {
if !executor.is_null() {
std::ptr::drop_in_place(executor);
pub unsafe extern "C" fn vm_exec_executor_destroy(executor_ptr: *mut vm_exec_executor_t) {
if !executor_ptr.is_null() {
let executor = Box::from_raw(executor_ptr as *mut CapiExecutor);
drop(executor)
}
}
7 changes: 4 additions & 3 deletions c-api/src/capi_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ pub unsafe extern "C" fn vm_exported_function_names(
/// C API function, works with raw object pointers.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn vm_exec_instance_destroy(instance: *mut vm_exec_instance_t) {
if !instance.is_null() {
std::ptr::drop_in_place(instance);
pub unsafe extern "C" fn vm_exec_instance_destroy(instance_ptr: *mut vm_exec_instance_t) {
if !instance_ptr.is_null() {
let instance = Box::from_raw(instance_ptr as *mut CapiInstance);
drop(instance);
}
}

Expand Down
6 changes: 3 additions & 3 deletions vm-executor-wasmer/src/wasmer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use multiversx_chain_vm_executor::{
Executor, ExecutorError, ExecutorLastError, ExecutorService, VMHooks,
};

// use log::LevelFilter;
// use crate::wasmer_logger as WasmerLogger;
use log::LevelFilter;
use crate::wasmer_logger as WasmerLogger;
use crate::WasmerExecutor;

#[derive(Default)]
Expand All @@ -22,7 +22,7 @@ impl BasicExecutorService {

fn init() {
// Initialize the logger only once (disable until we sync with node)
// WasmerLogger::init(LevelFilter::Off);
WasmerLogger::init(LevelFilter::Off);
}
}

Expand Down

0 comments on commit b464a6e

Please sign in to comment.