Any surety in a recognizance to keep the peace, or for good behavior, or both, shall have authority and right to take and surrender the principal and, upon the surrender, shall be discharged and exempted from all liability for any act of the principal, subsequent to the surrender, which would be a breach of the condition of the recognizance. The person so surrendered may recognize anew, with sufficient sureties, before any judge, for the residue of the term, and shall then be discharged.