LPS-46981 Properly close stream objects