[asterisk-commits] russell: trunk r111909 - in /trunk: doc/ include/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 17:50:46 CDT 2008


Author: russell
Date: Fri Mar 28 17:50:46 2008
New Revision: 111909

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111909
Log:
Make some notes about common usage of pbx_builtin_getvar_helper() that is not
thread-safe.

Modified:
    trunk/doc/janitor-projects.txt
    trunk/include/asterisk/pbx.h

Modified: trunk/doc/janitor-projects.txt
URL: http://svn.digium.com/view/asterisk/trunk/doc/janitor-projects.txt?view=diff&rev=111909&r1=111908&r2=111909
==============================================================================
--- trunk/doc/janitor-projects.txt (original)
+++ trunk/doc/janitor-projects.txt Fri Mar 28 17:50:46 2008
@@ -1,3 +1,15 @@
+ -- There a bunch of places where the result of pbx_builtin_getvar_helper()
+    gets stored and used.  This is not threadsafe.  This code should be replaced
+	with the following thread-safe version:
+
+	const char *var;
+
+	ast_channel_lock(chan);
+	if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
+		var = ast_strdupa(var);
+	}
+	ast_channel_unlock(chan);
+
  -- Convert all existing uses of astobj.h to astobj2.h
     -- (chan_sip already in progress in a branch)
 

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=111909&r1=111908&r2=111909
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Fri Mar 28 17:50:46 2008
@@ -800,6 +800,20 @@
 
 /*!
  * \note Will lock the channel.
+ *
+ * \note This function will return a pointer to the buffer inside the channel
+ * variable.  This value should only be accessed with the channel locked.  If
+ * the value needs to be kept around, it should be done by using the following
+ * thread-safe code:
+ * \code
+ *		const char *var;
+ *
+ *		ast_channel_lock(chan);
+ *		if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
+ *			var = ast_strdupa(var);
+ *		}
+ *		ast_channel_unlock(chan);
+ * \endcode
  */
 const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name);
 




More information about the asterisk-commits mailing list