Fixed memory leak caused by shadow variables