Port from mainline changes to fix cdbq shutdown memory leak