Fix double free of memory on cleanup.