fix leak in list_remove_if

This commit is contained in:
2025-04-12 20:49:55 +02:00
parent 5d98a06bf4
commit 5f5ea11549
2 changed files with 42 additions and 26 deletions

View File

@ -1,39 +1,48 @@
global ft_list_remove_if
extern free
section .text
;this function remove an element from a list, set the previous element to the next
; the element ot remove is in rax
; the previouse element is in r8
; the pointer to the start of the list is in rdi
remove_element:
push rsi
mov rsi, [rax + 8]
call call_free_elem
push rax
mov rax, [rax + 8]
test r8, r8
jz element_is_first
jz first_elem
mov [r8 + 8], rax
pop rax
mov [r8 + 8], rsi
jmp remove_element_end
first_elem:
mov [rdi], rsi
remove_element_end:
mov rax, rsi
pop rsi
ret
element_is_first:
mov [rdi], rax
pop rax
ret
;wants the element that needs to be freed in rax
call_free_elem:
push rdi
push rsi
push rdx
push rcx
push rax
push r8
push rax
mov rdi, [rax]
call rcx
pop rdi
call free wrt ..plt
pop r8
pop rax
pop rcx
pop rdx
pop rsi
@ -78,8 +87,9 @@ loop:
jz loop_end
mov rax, [rsp]
pop rax
call remove_element
jmp loop
loop_end:
@ -89,7 +99,5 @@ loop_end:
jmp loop
end:
ret