Fix panic by not closing unopened stuff