title: Got a problem with list creation function in generic linked list library
body: <p>I found a generic linked list library which I thought would be useful. But the llist_create(void *new_data) function is confusing me. The pointer new_list is allocated two times. What I can see is that the address returned by first malloc will be overwritten by second malloc. So why use the first malloc? (Code works perfectly)</p>
  
  <p>Since I got curious I tried to run by commenting the first malloc. Then gcc gave a warning "initialization from incompatible pointer type". Running the code gives segmentation fault.</p>
  
  <pre><code>struct node {
      void *data;
      struct node *next;
  };
  
  typedef struct node * llist;   
  
  
  llist *llist_create(void *new_data)
  {
      struct node *new_node;
  
      //First alloc
      llist *new_list = (llist *)malloc(sizeof (llist));
      //Second alloc
      *new_list = (struct node *)malloc(sizeof (struct node));
  
      new_node = *new_list;
      new_node-&gt;data = new_data;
      new_node-&gt;next = NULL;
      return new_list;
  }
  
   //Code which creates linked list in driver program
   llist *my_list = llist_create(NULL);
  </code></pre>