fix memory leaks in lists

This commit is contained in:
Folkert 2020-12-01 23:01:17 +01:00
parent 63f4fbf1ef
commit 5d00910a38
2 changed files with 24 additions and 7 deletions

View file

@ -604,7 +604,9 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
match expr {
Literal(literal) => build_exp_literal(env, literal),
RunLowLevel(op, symbols) => run_low_level(env, scope, parent, layout, *op, symbols),
RunLowLevel(op, symbols) => {
run_low_level(env, layout_ids, scope, parent, layout, *op, symbols)
}
ForeignCall {
foreign_symbol,
@ -1165,12 +1167,10 @@ fn list_literal<'a, 'ctx, 'env>(
let builder = env.builder;
let len_u64 = elems.len() as u64;
let elem_bytes = elem_layout.stack_size(env.ptr_bytes) as u64;
let ptr = {
let bytes_len = elem_bytes * len_u64;
let len_type = env.ptr_int();
let len = len_type.const_int(bytes_len, false);
let len = len_type.const_int(len_u64, false);
allocate_list(env, inplace, elem_layout, len)
@ -2410,6 +2410,7 @@ pub static COLD_CALL_CONV: u32 = 9;
fn run_low_level<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>,
layout: &Layout<'a>,
@ -2523,7 +2524,16 @@ fn run_low_level<'a, 'ctx, 'env>(
let inplace = get_inplace_from_layout(layout);
list_map(env, inplace, parent, func, func_layout, list, list_layout)
list_map(
env,
layout_ids,
inplace,
parent,
func,
func_layout,
list,
list_layout,
)
}
ListKeepIf => {
// List.keepIf : List elem, (elem -> Bool) -> List elem