title: SEGV: invalig write of size 8 when adding a node to the end of a linked list
body: <p>I've got this function:</p>
  
  <pre><code>int  list_add_elem_at_back(list_t *front_ptr, double elem)
  {
          list_t  item = malloc(sizeof(list_t));
          list_t  tmp = *front_ptr;
  
          if (item == NULL)
                  return (0);
          item-&gt;value = elem;
          item-&gt;next = NULL;
          while (tmp != NULL)
                  tmp = tmp-&gt;next;
          tmp-&gt;next = item;
          return (1);
  }
  </code></pre>
  
  <p>which is supposed to add a node to the back of the list starting with <code>t_list *front_ptr</code>.</p>
  
  <p><strong>FYI:</strong> <code>list_t</code> is an alias for <code>node_t *</code>.</p>
  
  <p>When executing it, I get a SegV crash, and the Valgrind logs are the following:</p>
  
  <pre><code>==3814== Invalid write of size 8
  ==3814==    at 0x4006C1: list_add_elem_at_back (simple_list.c:63)
  ==3814==    by 0x400A83: populate_list (simple_list.c:181)
  ==3814==    by 0x400B5C: main (simple_list.c:202)
  ==3814==  Address 0x521f048 is 0 bytes after a block of size 8 alloc'd
  ==3814==    at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
  ==3814==    by 0x40067D: list_add_elem_at_back (simple_list.c:56)
  ==3814==    by 0x400A83: populate_list (simple_list.c:181)
  ==3814==    by 0x400B5C: main (simple_list.c:202)
  ==3814== 
  ==3814== Invalid write of size 8
  ==3814==    at 0x4006EF: list_add_elem_at_back (simple_list.c:66)
  ==3814==    by 0x400A83: populate_list (simple_list.c:181)
  ==3814==    by 0x400B5C: main (simple_list.c:202)
  ==3814==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
  </code></pre>
  
  <p>The lines 63 and 66 are <code>item-&gt;next = NULL;</code> and <code>tmp-&gt;next = item;</code>, which make me think it comes from the way I allocated (or didn't ?) my memory for the "next" nodes, but I cannot find out what's wrong.</p>
  
  <p>Any help is appreciated.</p>