Fix leak in __enable_weak_this(). Thanks to Arthur O'Dwyer for finding it.

llvm-svn: 271487
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 7cf29e3468f7de38399abc756727f826ec6c6475
diff --git a/include/memory b/include/memory
index 0146352..8324d1c 100644
--- a/include/memory
+++ b/include/memory
@@ -4122,9 +4122,11 @@
         {
             if (__e && __e->__weak_this_.expired())
             {
-                __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e));
-                __e->__weak_this_.__cntrl_ = __cntrl_;
+                weak_ptr<_Yp> __tmp;
+                __tmp.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e));
+                __tmp.__cntrl_ = __cntrl_;
                 __cntrl_->__add_weak();
+                __e->__weak_this_.swap(__tmp);
             }
         }