pkg/proc: moving defer after error check