fixes to getprinc to prevent double free