fix: potential leak with gnl due to non-exhaustion

This commit is contained in:
Khaïs COLIN 2025-07-17 13:38:59 +02:00
parent 085a51ca6d
commit d7efc43f12
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 23 additions and 4 deletions

View file

@ -3,16 +3,17 @@
/* ::: :::::::: */
/* frees.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/25 17:46:01 by tchampio #+# #+# */
/* Updated: 2025/07/15 10:26:48 by tchampio ### ########.fr */
/* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */
/* Updated: 2025/07/17 14:00:01 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/cub3d_consts.h"
#include "../../includes/structs.h"
#include "../../mlx/mlx.h"
#include "../../includes/libft.h"
#include <stdlib.h>
void free_tab(char **tab)
@ -56,3 +57,19 @@ int destroy(t_cub3d_data *data)
exit(0);
return (0);
}
/*
Calls get_next_line in a loop until NULL is returned, freeing all data returned.
Ensures that all memory allocated by get_next_line is properly freed.
*/
void gnl_exhaust(int fd)
{
char *line;
line = get_next_line(fd);
while (line != NULL)
{
free(line);
line = get_next_line(fd);
}
}