How can I free the pointer in my linked list?
<p>Intro :<br />
The main function is meant to read from a FileDescriptor until it has found the EOF or a line feed. The size of my buffer is define by the user and you can use multiple FileDescriptor since my linked list is static.<br />
My problem :<br />
Depending on the size of the buffer (even or not), I get after the second call (if I don't free, it all works perfectly, but I'd rather not have memory leaks) :<br />
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug<br />
The only free I have is in my building function :<br /></p>

<pre><code>int gnl_build(int fd, char *buf, int ret, gnl_lst **head)
{
    gnl_lst *elem;
    char    *str;

    elem = *head;
    while (elem &amp;&amp; elem-&gt;fd != fd)
        elem = elem-&gt;next;
    if (elem == NULL)
    {
        //building new element
        elem = (gnl_lst *)lstnew(buf, (size_t)(ret + 1));
        elem-&gt;fd = fd;
        lstaddback((t_list **)head, (t_list *)elem);
    }
    else
    {
        //create new memory space and copies both strings in the new space
        str = strjoin(elem-&gt;content, buf);
        free((*elem).content);
        elem-&gt;content = str;
        elem-&gt;content_size = strlen(str) + 1;
    }
    if (strstr(elem-&gt;content, "\n") != NULL)
        return (1);
    return (0);
}
</code></pre>

<p>Any help is welcome ! Thanks.</p>