fix norm
This commit is contained in:
8
Makefile
8
Makefile
@ -21,7 +21,8 @@ SRCS_NAMES = malloc.c \
|
||||
free.c\
|
||||
realloc.c\
|
||||
utils.c\
|
||||
env_debug.c
|
||||
env_debug.c\
|
||||
program_end.c
|
||||
|
||||
SRCS_DIR = srcs
|
||||
|
||||
@ -39,8 +40,9 @@ LFT_DIR = libft/
|
||||
|
||||
all: libft_malloc.so
|
||||
|
||||
exec: $(OBJS_DIR) $(OBJS) $(LFT)
|
||||
$(CC) -o a.out $(FLAGS) main.c $(OBJS) $(LFT)
|
||||
exec: $(OBJS_DIR) $(NAME) $(LFT)
|
||||
$(CC) -o a.out $(FLAGS) main.c $(NAME) $(LFT)
|
||||
$(CC) -o a.out $(FLAGS) main.c -L. -lft_malloc $(LFT) -Wl,-rpath=.
|
||||
|
||||
libft_malloc.so: $(NAME)
|
||||
ln -sf $(NAME) libft_malloc.so
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/12/09 17:25:04 by tomoron ### ########.fr #
|
||||
# Updated: 2024/12/10 18:31:35 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -69,7 +69,7 @@ SRCS_BONUS = ft_lstnew.c\
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
OBJS_BONUS = $(SRCS_BONUS:.c=.o)
|
||||
|
||||
FLAGS = -Wall -Wextra -Werror -g
|
||||
FLAGS = -Wall -Wextra -Werror -g -fPIC
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 19:16:40 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 17:45:45 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:18:03 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_settings *get_settings()
|
||||
t_settings *get_settings(void)
|
||||
{
|
||||
static t_settings settings;
|
||||
char *str;
|
||||
@ -21,7 +21,7 @@ t_settings *get_settings()
|
||||
if (!settings.initialized)
|
||||
{
|
||||
if (getenv("MALLOC_SHOW_LEAKS"))
|
||||
settings.show_leaks = 0;
|
||||
settings.show_leaks = 1;
|
||||
str = getenv("MALLOC_DEBUG_LEVEL");
|
||||
if (!str || !ft_strcmp(str, "NONE"))
|
||||
settings.debug_level = 0;
|
||||
|
13
srcs/free.c
13
srcs/free.c
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 18:46:07 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 19:16:14 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 19:13:55 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,23 +43,20 @@ int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur, char *fnc)
|
||||
while (cur)
|
||||
{
|
||||
if (cur->next == *alloc)
|
||||
{
|
||||
*res = cur;
|
||||
return (1);
|
||||
}
|
||||
if ((cur->next > *alloc || cur->next == 0) && cur <= *alloc && \
|
||||
((t_ul)(*alloc) - (t_ul)cur) <= cur->size)
|
||||
{
|
||||
log_str("invalid pointer but adress is inside of an \
|
||||
allocation", 2, 1, 1);
|
||||
log_str("invalid pointer but address is known", 2, 1, 1);
|
||||
*alloc = cur;
|
||||
*res = prev;
|
||||
return (1);
|
||||
}
|
||||
if(*res)
|
||||
return(1);
|
||||
prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
log_str("invalid pointer inside of a chunk", 2, 1, 1);
|
||||
log_str("invalid pointer inside of a chunk", 3, 1, 1);
|
||||
invalid_pointer(fnc);
|
||||
return (0);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 17:53:13 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:19:55 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -68,7 +68,7 @@ extern pthread_mutex_t g_mallock;
|
||||
size_t align(size_t nb, size_t align_nb);
|
||||
|
||||
void *malloc(size_t size);
|
||||
t_settings *get_settings();
|
||||
t_settings *get_settings(void);
|
||||
void show_alloc_mem(void);
|
||||
void free(void *ptr);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/23 17:19:59 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 18:48:53 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:12:18 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/03 18:44:32 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 18:21:47 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:18:45 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
25
srcs/program_end.c
Normal file
25
srcs/program_end.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* program_end.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 17:11:27 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:13:37 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void __attribute__((destructor)) malloc_end(void)
|
||||
{
|
||||
if (get_settings()->show_leaks)
|
||||
{
|
||||
ft_putstr_fd("\n\033[31m\033[1mMALLOC_SHOW_LEAKS is defined, here is \
|
||||
the leak report\n", 1);
|
||||
show_alloc_mem();
|
||||
ft_putstr_fd("\033[0m", 1);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/02 14:41:22 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 20:07:24 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:14:56 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -53,10 +53,12 @@ static void *realloc_prealloc(t_alloc *alloc, t_mem_chunk *chunk, \
|
||||
|| (size > SMALL_MALLOC && is_small == 1)
|
||||
|| (t_ul)(alloc->next) - (t_ul)(alloc + 1) < size)
|
||||
{
|
||||
log_str("new realloc size doesn't fit in the current position, reallocating", 3, 1, 1);
|
||||
log_str("new realloc size doesn't fit in the current position, \
|
||||
reallocating", 3, 1, 1);
|
||||
return (realloc_recreate(alloc, size));
|
||||
}
|
||||
log_str("new realloc size fits in the current position, making it bigger",3, 1, 1);
|
||||
log_str("new realloc size fits in the current position, making it \
|
||||
bigger", 3, 1, 1);
|
||||
chunk->space_left -= size - alloc->size;
|
||||
alloc->size = size;
|
||||
return (alloc + 1);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/03 13:20:54 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/09 18:11:39 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/12/10 18:16:13 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user