mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
fix(c-api) Remove the memory leak in wasm_tabletype_element.
This commit is contained in:
@@ -12,6 +12,7 @@ const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
|
|||||||
pub(crate) struct WasmTableType {
|
pub(crate) struct WasmTableType {
|
||||||
pub(crate) table_type: TableType,
|
pub(crate) table_type: TableType,
|
||||||
limits: Box<wasm_limits_t>,
|
limits: Box<wasm_limits_t>,
|
||||||
|
content: Box<wasm_valtype_t>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WasmTableType {
|
impl WasmTableType {
|
||||||
@@ -20,8 +21,13 @@ impl WasmTableType {
|
|||||||
min: table_type.minimum as _,
|
min: table_type.minimum as _,
|
||||||
max: table_type.maximum.unwrap_or(LIMITS_MAX_SENTINEL),
|
max: table_type.maximum.unwrap_or(LIMITS_MAX_SENTINEL),
|
||||||
});
|
});
|
||||||
|
let content = Box::new(table_type.ty.into());
|
||||||
|
|
||||||
Self { table_type, limits }
|
Self {
|
||||||
|
table_type,
|
||||||
|
limits,
|
||||||
|
content,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,15 +83,9 @@ pub unsafe extern "C" fn wasm_tabletype_limits(table_type: &wasm_tabletype_t) ->
|
|||||||
table_type.inner().limits.as_ref()
|
table_type.inner().limits.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix memory leak
|
|
||||||
// this function leaks memory because the returned limits pointer is not owned
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasm_tabletype_element(
|
pub unsafe extern "C" fn wasm_tabletype_element(table_type: &wasm_tabletype_t) -> &wasm_valtype_t {
|
||||||
table_type: &wasm_tabletype_t,
|
table_type.inner().content.as_ref()
|
||||||
) -> *const wasm_valtype_t {
|
|
||||||
let table_type = table_type.inner().table_type;
|
|
||||||
|
|
||||||
Box::into_raw(Box::new(table_type.ty.into()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
Reference in New Issue
Block a user