Fixing memory leak caused by capturing a shared_ptr in continuation lambda