Просмотр исходного кода

modules_k/dialog: Improve dialog timer list handling.

- Avoid updating a dialog timer item if it is not yet linked into
  the timer list.
  (Avoids reference counting bugs due to race conditions where the
  timer list has not been initialized yet prior to any update
  attempts.)
- In case of bogus dialog during timer insertion, postpone release
  of dialog timer lock until error log message has been emitted.
Timo Reimann 14 лет назад
Родитель
Сommit
7afb2cf8e4
1 измененных файлов с 7 добавлено и 8 удалено
  1. 7 8
      modules_k/dialog/dlg_timer.c

+ 7 - 8
modules_k/dialog/dlg_timer.c

@@ -133,9 +133,9 @@ int insert_dlg_timer(struct dlg_tl *tl, int interval)
 	lock_get( d_timer->lock);
 
 	if (tl->next!=0 || tl->prev!=0) {
-		lock_release( d_timer->lock);
 		LM_CRIT("Trying to insert a bogus dlg tl=%p tl->next=%p tl->prev=%p\n",
 			tl, tl->next, tl->prev);
+		lock_release( d_timer->lock);
 		return -1;
 	}
 	tl->timeout = get_ticks()+interval;
@@ -202,14 +202,13 @@ int update_dlg_timer(struct dlg_tl *tl, int timeout)
 {
 	lock_get( d_timer->lock);
 
-	if ( tl->next ) {
-		if (tl->prev==0) {
-			lock_release( d_timer->lock);
-			return -1;
-		}
-		remove_dialog_timer_unsafe(tl);
+	if (tl->next==0 || tl->prev==0) {
+		LM_CRIT("Trying to update a bogus dlg tl=%p tl->next=%p tl->prev=%p\n",
+			tl, tl->next, tl->prev);
+		lock_release( d_timer->lock);
+		return -1;
 	}
-
+	remove_dialog_timer_unsafe( tl );
 	tl->timeout = get_ticks()+timeout;
 	insert_dialog_timer_unsafe( tl );