[asterisk-commits] mmichelson: trunk r371572 - in /trunk: ./ res/res_rtp_asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 20 15:19:55 CDT 2012


Author: mmichelson
Date: Mon Aug 20 15:19:52 2012
New Revision: 371572

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=371572
Log:
Use thread-local storage to store pj_thread_descs.

pj_thread_register() takes a parameter of type pj_thread_desc.
It was assumed that pj_thread_register either used this item
temporarily or made a copy of it. Unfortunately, all it does is
keep a pointer to the structure in thread-local storage. This
means that if our pj_thread_desc goes out of scope, then pjlib
will be referencing bogus data quite often, most commonly on
operations involving a pj_mutex_t.

In our case, our pj_thread_desc was on the stack and went out
of scope very shortly after registering our thread with pjlib.
With this change, the pj_thread_desc is stored in thread-local
storage so the pointer that pjlib keeps in thread-local storage
will reference legitimate memory.

(closes issue ASTERISK-20237)
reported by Jeremy Pepper
Patches:
	ASTERISK-20237.patch uploaded by Mark Michelson (license #5049)
Tested by Jeremy Pepper
........

Merged revisions 371571 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    trunk/   (props changed)
    trunk/res/res_rtp_asterisk.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-11-merged (original)
+++ branch-11-merged Mon Aug 20 15:19:52 2012
@@ -1,1 +1,1 @@
-/branches/11:1-371121,371143,371146,371200,371227,371258,371272,371295,371324,371355,371382,371395,371399,371425-371426,371438,371482,371492,371507,371516,371518,371520,371546
+/branches/11:1-371121,371143,371146,371200,371227,371258,371272,371295,371324,371355,371382,371395,371399,371425-371426,371438,371482,371492,371507,371516,371518,371520,371546,371571

Modified: trunk/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_rtp_asterisk.c?view=diff&rev=371572&r1=371571&r2=371572
==============================================================================
--- trunk/res/res_rtp_asterisk.c (original)
+++ trunk/res/res_rtp_asterisk.c Mon Aug 20 15:19:52 2012
@@ -416,17 +416,29 @@
 	ao2_ref(remote_candidate, -1);
 }
 
+AST_THREADSTORAGE(pj_thread_storage);
+
 /*! \brief Function used to check if the calling thread is registered with pjlib. If it is not it will be registered. */
 static void pj_thread_register_check(void)
 {
-	pj_thread_desc desc;
+	pj_thread_desc *desc;
 	pj_thread_t *thread;
 
 	if (pj_thread_is_registered() == PJ_TRUE) {
 		return;
 	}
 
-	pj_thread_register("Asterisk Thread", desc, &thread);
+	desc = ast_threadstorage_get(&pj_thread_storage, sizeof(pj_thread_desc));
+	if (!desc) {
+		ast_log(LOG_ERROR, "Could not get thread desc from thread-local storage. Expect awful things to occur\n");
+		return;
+	}
+	pj_bzero(*desc, sizeof(*desc));
+
+	if (pj_thread_register("Asterisk Thread", *desc, &thread) != PJ_SUCCESS) {
+		ast_log(LOG_ERROR, "Coudln't register thread with PJLIB.\n");
+	}
+	return;
 }
 
 /*! \brief Helper function which updates an ast_sockaddr with the candidate used for the component */




More information about the asterisk-commits mailing list