The line newNode->next = NULL; is safe and does not cause undefined behavior until u miss these points given below: 1)The memory allocation succeeds. 2)Other threads cannot access newNode during initialization.