fix infinite loop in recursive safe_link