Repository: trafficserver
Updated Branches:
  refs/heads/master 10a361304 -> 74e2bb7be


TS-3156: Fix crash for MutexTryLock::acquire()


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/74e2bb7b
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/74e2bb7b
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/74e2bb7b

Branch: refs/heads/master
Commit: 74e2bb7bee07d265ad6537da9b5755304257c576
Parents: 10a3613
Author: Alan M. Carroll <[email protected]>
Authored: Thu Nov 20 16:11:53 2014 -0600
Committer: Alan M. Carroll <[email protected]>
Committed: Thu Nov 20 20:57:35 2014 -0600

----------------------------------------------------------------------
 iocore/eventsystem/I_Lock.h | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/74e2bb7b/iocore/eventsystem/I_Lock.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/I_Lock.h b/iocore/eventsystem/I_Lock.h
index d69a364..bb3d2f3 100644
--- a/iocore/eventsystem/I_Lock.h
+++ b/iocore/eventsystem/I_Lock.h
@@ -471,42 +471,38 @@ class MutexTryLock
 {
 private:
   Ptr<ProxyMutex> m;
-  volatile bool lock_acquired;
+  bool lock_acquired;
 
 public:
   MutexTryLock(
 #ifdef DEBUG
                   const char *afile, int aline, const char *ahandler,
 #endif                          //DEBUG
-                  ProxyMutex * am, EThread * t)
+                  ProxyMutex * am, EThread * t) : m(am)
   {
       lock_acquired = Mutex_trylock(
 #ifdef DEBUG
                                      afile, aline, ahandler,
 #endif //DEBUG
-                                     am, t);
-      if (lock_acquired)
-        m = am;
+                                     m, t);
   }
 
   MutexTryLock(
 #ifdef DEBUG
                 const char *afile, int aline, const char *ahandler,
 #endif                          //DEBUG
-                ProxyMutex * am, EThread * t, int sp)
+                ProxyMutex * am, EThread * t, int sp) : m(am)
   {
       lock_acquired = Mutex_trylock_spin(
 #ifdef DEBUG
                                           afile, aline, ahandler,
 #endif //DEBUG
-                                          am, t, sp);
-      if (lock_acquired)
-        m = am;
+                                          m, t, sp);
   }
 
   ~MutexTryLock()
   {
-    if (m.m_ptr)
+    if (lock_acquired)
       Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding);
   }
 
@@ -520,10 +516,9 @@ public:
 
   void release()
   {
-    ink_assert(m.m_ptr);
-    if (m.m_ptr) {
+    ink_assert(lock_acquired); // generate a warning because it shouldn't be 
done.
+    if (lock_acquired) {
       Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding);
-      m.clear();
     }
     lock_acquired = false;
   }

Reply via email to