Created by: CoZZmOnAvT
Interesting bug with compilator optimization. Code written in C.
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)
gcc -g3 -Wextra -Werror -Wall -O2 -fdata-sections -ffunction-sections
else
{
err = "Some string";
ft_dlstpush(&list, ft_dlstnew(some_ptr, sizeof(void *)));
}
list
- It's a simple storage for pointers, this storage circulary double-linked, so it has root, empty node without data.
if this block is written as:
else if ((err = "Some string"))
ft_dlstpush(&list, ft_dlstnew(some_ptr, sizeof(void *)));
No leak detected.
This is the structure of list node.
typedef struct s_dlist
{
struct s_dlist *prev;
void *content;
size_t content_size;
struct s_dlist *next;
} t_dlist;
void ft_dlstpush(t_dlist **dest, t_dlist *src)
{
if (!dest || !src)
return ;
!*dest ? *dest = ft_dlstnew(NULL, 0) : 0;
(*dest)->next->prev = src;
src->next = (*dest)->next;
src->prev = *dest;
(*dest)->next = src;
}
t_dlist *ft_dlstnew(void *content, size_t content_size)
{
t_dlist *new;
if (!(new = malloc(sizeof(t_dlist))))
return (NULL);
new->prev = new;
new->next = new;
new->content = content;
new->content_size = content ? content_size : 0;
return (new);
}
Disassembling two object binaries (with optimization and without) gives no difference.