Fixed linked list
Memory problem fixed by allocating the memory at the appropriate function level.