Fixed memory leak at buffer generation