fix double-free bug