Fixed invalid pointer free bug