§ 246-a. Bail bond to act as lien on real estate. Upon the execution of any bail bond and an affidavit of justification as set forth in the provisions of subdivision four of section 520.20 of the criminal procedure law, between any person or corporation and the people of the state of New York, there shall attach to the real property described in the said affidavit of justification as hereinafter provided, a lien in favor of the bail bond, which lien shall remain in full force and effect until a certificate of discharge has been filed pursuant to the provisions of section two hundred and forty-six or such lien has been discharged pursuant to the provisions of section two hundred and forty-eight of the lien law. Whenever final judgment has been rendered in the criminal action or proceeding for which such bail bond shall have been executed or whenever the bail has been exonerated by order of the court, the attorney general of the state of New York or the district attorney of the county in which such action or proceeding is pending or maintained, shall execute a certificate of discharge of such lien, provided it shall appear that the prosecution has lost no right thereunder.