fix memleak on shutdown