I want to create a list with the following structure:

* list.h: Contains function prototypes and defines data types
* lt.c: main function to test the list
* list.c: actual implementation of the list

When executing it I always get a segfault error. When trying to identify it with gdb it is shown that it is the fault of the following line in lt.c: 

```
list_t *li=list_init();

```

The rest of my lt.c file looks as follows:

```
#include <stdio.h>
#include <stdlib.h>
#include "list.h"

int main ( int argc, char *argv [ ], char *envp [ ] )
{
    list_t *li=list_init();
//li=list_init();
   /* if((li=list_init())==NULL)
    {
        perror (" Cannot allocate memory" ) ;
        exit(-1);
    }*/
}

```

My implementation of the list.c function list\_init() is as follows:

```
list_t *list_init ()
{
    list_t* newlist = malloc(sizeof(*newlist));
if (!newlist)
{
    perror ("malloc-newlist");
    exit (EXIT_FAILURE);
}`enter code here`
   //newlist->first=NULL;
    //newlist->last=NULL;
newlist->first = (struct list_elem *) malloc(sizeof(struct list_elem));
newlist->last  = (struct list_elem *) malloc(sizeof(struct list_elem));
    return newlist;
}

```

My list.h file is as follows:

```
    struct list_elem {
    struct list_elem *next; // Zeiger auf das naechste Element
    char         *data; // Zeiger auf ein Datenobject
};

typedef struct list {
    struct list_elem *first;// erstes Element in der Liste
    struct list_elem *last; // letztes Element in der Liste
} list_t;

/* function prototypes */
list_t           *list_init ();

```

However, I do not know how I could change the implementation so that it does not occur anymore.
Thank you very much for your help.