CHOP-52. Ensure all resources get closed properly.

Reviewed by: kiyan