Check for NULL after attempting to allocate memory for a new node.