Fixed copy generation functions memory leak