fix for TS-2779 (atscppapi: bug in AsyncTimer - cancel results in crash); This 
closes #77


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

Branch: refs/heads/master
Commit: 92ad666f9e7d102c549aa381620cfed89fc9ec57
Parents: bc975cc
Author: Manjesh Nilange <[email protected]>
Authored: Mon May 5 13:48:35 2014 -0700
Committer: Manjesh Nilange <[email protected]>
Committed: Wed May 21 11:52:46 2014 -0700

----------------------------------------------------------------------
 lib/atscppapi/src/AsyncTimer.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/92ad666f/lib/atscppapi/src/AsyncTimer.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/AsyncTimer.cc b/lib/atscppapi/src/AsyncTimer.cc
index d07b617..4604375 100644
--- a/lib/atscppapi/src/AsyncTimer.cc
+++ b/lib/atscppapi/src/AsyncTimer.cc
@@ -45,7 +45,7 @@ int handleTimerEvent(TSCont cont, TSEvent event, void *edata) 
{
   AsyncTimerState *state = static_cast<AsyncTimerState *>(TSContDataGet(cont));
   if (state->initial_timer_action_) {
     LOG_DEBUG("Received initial timer event.");
-    state->initial_timer_action_ = NULL; // mark it so that it won't be 
canceled in the destructor
+    state->initial_timer_action_ = NULL; // mark it so that it won't be 
canceled later on
     if (state->type_ == AsyncTimer::TYPE_PERIODIC) {
       LOG_DEBUG("Scheduling periodic event now");
       state->periodic_timer_action_ = TSContScheduleEvery(state->cont_, 
state->period_in_ms_,
@@ -91,6 +91,10 @@ void AsyncTimer::run() {
 }
 
 void AsyncTimer::cancel() {
+  if (!state_->cont_) {
+    LOG_DEBUG("Already canceled");
+    return;
+  }
   TSMutexLock(TSContMutexGet(state_->cont_)); // mutex will be unlocked in 
destroy
   if (state_->initial_timer_action_) {
     LOG_DEBUG("Canceling initial timer action");
@@ -102,6 +106,7 @@ void AsyncTimer::cancel() {
   }
   LOG_DEBUG("Destroying cont");
   TSContDestroy(state_->cont_);
+  state_->cont_ = NULL;
 }
 
 AsyncTimer::~AsyncTimer() {

Reply via email to