ported back memory leak fix