fix a memory leak on shutdown