[3.5.x] Some fixes for the safe_open() function.