fix mem invalid read/write