fix HOSTTYPE setting even if env var is set. changes to free to not unmap first chunk and add env setting NO_UNMAP
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 19:16:40 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/14 17:24:10 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/03/20 16:58:18 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,6 +21,8 @@ t_settings *get_settings(void)
|
||||
{
|
||||
if (getenv("MALLOC_SHOW_LEAKS"))
|
||||
settings.show_leaks = 1;
|
||||
if (getenv("MALLOC_NO_UNMAP"))
|
||||
settings.no_unmap = 1;
|
||||
str = getenv("MALLOC_DEBUG_LEVEL");
|
||||
if (!str || !ft_strcmp(str, "NONE"))
|
||||
settings.debug_level = 0;
|
||||
|
26
srcs/free.c
26
srcs/free.c
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 18:46:07 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/14 17:20:17 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/03/20 17:00:04 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -61,6 +61,24 @@ int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur, char *fnc)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void free_chunk(size_t size, t_mem_chunk *chunk, t_mem_chunk **main_chunk)
|
||||
{
|
||||
t_mem_chunk *prev;
|
||||
|
||||
prev = *main_chunk;
|
||||
if(*main_chunk == chunk)
|
||||
prev = 0;
|
||||
while(prev && prev->next != chunk)
|
||||
prev = prev->next;
|
||||
if (!prev && !chunk->next)
|
||||
return;
|
||||
if(prev)
|
||||
prev->next = chunk->next;
|
||||
else
|
||||
*main_chunk = chunk->next;
|
||||
munmap(chunk, size);
|
||||
}
|
||||
|
||||
static int free_prealloc(t_alloc *alloc, t_mem_chunk **main_chunk, \
|
||||
int is_small)
|
||||
{
|
||||
@ -79,15 +97,13 @@ static int free_prealloc(t_alloc *alloc, t_mem_chunk **main_chunk, \
|
||||
chunk->first = alloc->next;
|
||||
else if (prev)
|
||||
prev->next = alloc->next;
|
||||
if (!chunk->first)
|
||||
if (!chunk->first && !get_settings()->no_unmap)
|
||||
{
|
||||
if (*main_chunk == chunk)
|
||||
*main_chunk = chunk->next;
|
||||
if (is_small)
|
||||
size = SMALL_CHUNK_SIZE;
|
||||
else
|
||||
size = TINY_CHUNK_SIZE;
|
||||
munmap(chunk, size);
|
||||
free_chunk(size, chunk, main_chunk);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/15 15:00:21 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/03/20 16:58:10 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,6 +57,7 @@ typedef struct t_settings
|
||||
{
|
||||
uint8_t debug_level:2;
|
||||
uint8_t show_leaks:1;
|
||||
uint8_t no_unmap:1;
|
||||
uint8_t initialized:1;
|
||||
} t_settings; //size 1
|
||||
|
||||
|
Reference in New Issue
Block a user