fix alloc between two allocations, fix free (uninitialized value)
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 18:46:07 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/01 03:16:19 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/01 18:47:12 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -54,6 +54,7 @@ int free_prealloc(t_alloc *alloc, t_mem_bloc **main_bloc, size_t size)
|
||||
t_mem_bloc *bloc;
|
||||
t_alloc *prev;
|
||||
|
||||
prev = 0;
|
||||
bloc = get_alloc_bloc(alloc, *main_bloc, size);
|
||||
if(!bloc)
|
||||
return(0);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/23 17:19:59 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/01 03:05:08 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/01 19:21:27 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -58,14 +58,21 @@ t_alloc *get_suitable_addr_in_bloc(t_mem_bloc *bloc, size_t size)
|
||||
size_t space_left;
|
||||
size_t free_space;
|
||||
|
||||
tmp = bloc->first; //alloc when first alloc has been removed
|
||||
tmp = bloc->first;
|
||||
space_left = bloc->space_left;
|
||||
if((t_ul)bloc->first - (t_ul)(bloc + 1) >= size + sizeof(t_alloc))
|
||||
{
|
||||
tmp = bloc->first;
|
||||
bloc->first = reserve_addr((void *)(bloc + 1), size, 0, bloc) - 1;
|
||||
bloc->first->next = tmp;
|
||||
return(bloc->first + 1);
|
||||
}
|
||||
while (tmp->next)
|
||||
{
|
||||
free_space = ((t_ul)tmp->next - (t_ul)tmp) - (tmp->size + sizeof(t_alloc));
|
||||
if (free_space >= size + sizeof(t_alloc))
|
||||
return (reserve_addr(
|
||||
(void *)((char *)tmp->next + tmp->size + sizeof(t_alloc)),
|
||||
(void *)((char *)tmp + tmp->size + sizeof(t_alloc)),
|
||||
size, tmp, bloc));
|
||||
space_left -= free_space;
|
||||
tmp = tmp->next;
|
||||
|
Reference in New Issue
Block a user