Browse Source

HPCC-14584 Avoid potential exception in call from destructor

With the c++11 semantics enabled, throwing an exception directly
or indirectly from a desctructor that hasn't been declared with
noexcept(false) will terminate the program.

The locking code prior to this change had a wrapper class that
during destruction called a method that could throw an exception.
Avoid the use of this simple wrapper class and call the methods
it was calling in the ctor and dtor directly to avoid being hit
by the new c++11 semantics.
NB: alternative fix was to add noexcept(false) to dtor, but
avoiding the possibility of an exception in destructor altogether
is safer.

Signed-off-by: Jake Smith <jake.smith@lexisnexis.com>
Jake Smith 9 năm trước cách đây
mục cha
commit
dd26b1d640
1 tập tin đã thay đổi với 8 bổ sung13 xóa
  1. 8 13
      dali/base/dasds.cpp

+ 8 - 13
dali/base/dasds.cpp

@@ -3284,15 +3284,6 @@ class CLock : public CInterface, implements IInterface
 
     LockStatus doLock(unsigned mode, unsigned timeout, ConnectionId id, SessionId sessionId, IUnlockCallback &callback, bool change=false)
     {
-        class CLockCallbackUnblock
-        {
-        public:
-            CLockCallbackUnblock(IUnlockCallback &_callback) : callback(_callback) { callback.unblock(); }
-            ~CLockCallbackUnblock() { callback.block(); }
-        private:
-            IUnlockCallback &callback;
-        };
-
         if (INFINITE == timeout)
         {
             loop
@@ -3308,8 +3299,9 @@ class CLock : public CInterface, implements IInterface
                     waiting++;
                     {
                         CHECKEDCRITICALUNBLOCK(crit, fakeCritTimeout);
-                        CLockCallbackUnblock cb(callback);
+                        callback.unblock();
                         timedout = !sem.wait(LOCKSESSCHECK);
+                        callback.block();
                     }
                     if (timedout)
                     {
@@ -3322,8 +3314,9 @@ class CLock : public CInterface, implements IInterface
                         }
                         {
                             CHECKEDCRITICALUNBLOCK(crit, fakeCritTimeout);
-                            CLockCallbackUnblock cb(callback);
+                            callback.unblock();
                             validateConnectionSessions();
+                            callback.block();
                         }
                     }
                 }
@@ -3345,10 +3338,11 @@ class CLock : public CInterface, implements IInterface
                     waiting++;
                     {
                         CHECKEDCRITICALUNBLOCK(crit, fakeCritTimeout);
-                        CLockCallbackUnblock cb(callback);
+                        callback.unblock();
                         unsigned remaining;
                         if (tm.timedout(&remaining) || !sem.wait(remaining>LOCKSESSCHECK?LOCKSESSCHECK:remaining))
                             timedout = true;
+                        callback.block();
                     }
                     if (timedout) {
                         if (!sem.wait(0))
@@ -3357,8 +3351,9 @@ class CLock : public CInterface, implements IInterface
                         bool disconnects;
                         {
                             CHECKEDCRITICALUNBLOCK(crit, fakeCritTimeout);
-                            CLockCallbackUnblock cb(callback);
+                            callback.unblock();
                             disconnects = validateConnectionSessions();
+                            callback.block();
                         }
                         if (tm.timedout())
                         {