If no party is aggrieved by the misconduct of the accused, the order must, and, in any case where the court thinks proper so to direct, it may, direct the prosecution of the undertaking, by the attorney-general, or by the district attorney of the county in which it was given, in the name of the people. In an action, brought pursuant to the order, the people are entitled to recover the entire sum, specified in the undertaking. Out of the money collected, the court, which directed the prosecution, must direct that the person, at whose instance the warrant was issued, be paid such a sum as it thinks proper, to satisfy the costs and expenses incurred by him, and to compensate him for any loss or injury sustained by him, by reason of the misconduct. The residue of the money must be paid into the treasury of the state.
N.Y. Jud. Law § 779