Which means that you need
temp->line = malloc(strlen(str)+1);

before you do this
strcpy(temp->line,str);