If the defendant gives to the plaintiff a bond with sufficient surety to be approved by the sheriff before the return of the attachment or by the court or justice of the peace (as the case may be), after the return thereof to pay any judgment recovered against the defendant with costs, the property attached and the garnishee summoned shall be discharged.