heap: fix memory leak in destructor

fixes #8977