buffer memory leak fix and internal transformation memory leak fix