Add null check when calling strdup