소스 검색

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 년 전
부모
커밋
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 );