Fixing a memory leak