Fix two crashes at once (uninited pointer & stream closed too early)