Fixed memory leak when exiting while syncing