Fix pack_close: read fields before freeing the struct.