fix potential invalid pointer problem