Section 31D. Whenever an officer or employee or former officer or employee of the commonwealth dies, and the commonwealth owes that officer or employee any sum or sums, by reason of services rendered or by reason of the terms of the officer or employee’s employment, the comptroller may issue such sums to the beneficiaries designated to the employee under section 31A. Payments made as provided in this section shall discharge the liability of the commonwealth to all persons with respect to such sum or sums.