Pārlūkot izejas kodu

modules_k/dialog: Improve error handling during dialog creation.

- Set current dialog only after all other setup work succeeded.
  (Eliminates call to profile_cleanup() and guarantees that dialog
  profiling does not yield to segfault if dialog creation fails
  for certain reasons.)
- During error handling, refrain from decrementing the reference
  counter for dialog linking if this is a spiraled request
  (because positive spiral detection skips the linkage code path).
Timo Reimann 14 gadi atpakaļ
vecāks
revīzija
71dd754818
1 mainītis faili ar 7 papildinājumiem un 7 dzēšanām
  1. 7 7
      modules_k/dialog/dlg_handlers.c

+ 7 - 7
modules_k/dialog/dlg_handlers.c

@@ -846,11 +846,6 @@ int dlg_new_dialog(struct sip_msg *req, struct cell *t, const int run_initial_cb
     if_update_stat( dlg_enable_stats, processed_dlgs, 1);
 
 finish:
-
-    set_current_dialog(req, dlg);
-    _dlg_ctx.dlg = dlg;
-    ref_dlg(dlg, 1);
-
 	if (t) {
 		// transaction exists ==> keep ref counter large enough to
 		// avoid premature cleanup and ensure proper dialog referencing
@@ -870,10 +865,15 @@ finish:
         }
 	}
 
+    set_current_dialog(req, dlg);
+    _dlg_ctx.dlg = dlg;
+    ref_dlg(dlg, 1);
+
 	return 0;
+
 error:
-	unref_dlg(dlg,1);                   // undo ref regarding linking
-	profile_cleanup(req, 0, NULL);      // undo ref regarding setting current dialog
+	if (!spiral_detected)
+		unref_dlg(dlg,1);               // undo ref regarding linking
 	return -1;
 }