Section 40. Bonds given to the commonwealth, any county, city, town or political subdivision to secure the performance of contracts for the construction or repair of public buildings or other public works may be discharged or released by the awarding authority, upon such terms as it deems expedient, after the expiration of one year from the time of completion, subject to section thirty-nine K, of the work contracted to be done; provided that no claim filed under said bond is pending, and provided further, that no such bonds shall be discharged or released prior to the expiration of all special guarantees provided for in the contract unless new bonds in substitution therefor specifically relating to the unexpired guarantees shall be taken.