From 542adefac13cebc236df63a68161fc6922a5510c Mon Sep 17 00:00:00 2001
From: Paul Licameli <paul.licameli@audacityteam.org>
Date: Sun, 12 Aug 2018 15:55:27 -0400
Subject: [PATCH] Bug1931:  more precautions, higher level and more general...

... Do for release as was already done for click and drag:  hold a shared
pointer.

This will protect against reentrancy surprises as in this bug, where a
reference to the handle may be removed during one of the handle's own
methods.
---
 src/CellularPanel.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/CellularPanel.cpp b/src/CellularPanel.cpp
index d7b3b2363..31c3254d6 100644
--- a/src/CellularPanel.cpp
+++ b/src/CellularPanel.cpp
@@ -729,13 +729,15 @@ try
       }
       else if (event.ButtonUp()) {
          // UIHANDLE RELEASE
+         // copy shared_ptr for safety, as in HandleClick
+         auto handle = state.mUIHandle;
          unsigned moreFlags = state.mMouseOverUpdateFlags;
          UIHandle::Result refreshResult =
-            state.mUIHandle->Release( tpmEvent, GetProject(), this );
+            handle->Release( tpmEvent, GetProject(), this );
          ProcessUIHandleResult
             (pClickedCell.get(), pCell.get(),
              refreshResult | moreFlags);
-         state.mUIHandle.reset(), ClearTargets();
+         state.mUIHandle.reset(), handle.reset(), ClearTargets();
          state.mpClickedCell.reset();
          // will also Uncapture() below
       }