Fixed ticket #939: Throwing exception inside exception handler will cause infinite loop (thanks Roman Puls for the report)
 - exception handler is now popped from the stack immediately in PJ_THROW


git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2878 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/except.c b/pjlib/src/pj/except.c
index 66aa56e..61c882c 100644
--- a/pjlib/src/pj/except.c
+++ b/pjlib/src/pj/except.c
@@ -50,6 +50,7 @@
         pj_assert(handler != NULL);
         /* This will crash the system! */
     }
+    pj_pop_exception_handler_(handler);
     pj_longjmp(handler->state, exception_id);
 }
 
@@ -86,14 +87,15 @@
     pj_thread_local_set(thread_local_id, rec);
 }
 
-PJ_DEF(void) pj_pop_exception_handler_(void)
+PJ_DEF(void) pj_pop_exception_handler_(struct pj_exception_state_t *rec)
 {
     struct pj_exception_state_t *handler;
 
     handler = (struct pj_exception_state_t *)
 	      pj_thread_local_get(thread_local_id);
-    pj_assert(handler != NULL);
-    pj_thread_local_set(thread_local_id, handler->prev);
+    if (handler && handler==rec) {
+	pj_thread_local_set(thread_local_id, handler->prev);
+    }
 }
 #endif