fix Memory modified after free problem