Any surety upon a bail bond of any person charged with a violation of a provision of this Code or a city ordinance, or of any offense over which the municipal court has jurisdiction, may surrender his principal at any time to the director of public safety or chief of police, who shall confine such principal, until discharged by order of the judge of the municipal court, or other proper officer, or by giving other and good security. The delivery of the principal as provided in this section shall discharge the sureties of all further liability upon such bond; provided, that delivery shall be before any judgment of forfeiture upon the bond shall have been entered.