I think its probably fine, you probably don't need to set it to NULL, just overwrite it if you have a user_domain  if you have a the value in the configuration 

feel free to update krb5_principal_set_realm() to no leave NULL realm in cause of strdup() failure.

I'm not that worried about that case (even you though you guys are), so other code will soon abort() or crash if you run of of memory anyway.