From: Russell Bryant Date: Fri, 28 Mar 2008 22:50:46 +0000 (+0000) Subject: Make some notes about common usage of pbx_builtin_getvar_helper() that is not X-Git-Tag: 1.6.2.0-beta1~2587 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=afd878357717fc46e8edc3369216aa6e5de2e80c;p=thirdparty%2Fasterisk.git Make some notes about common usage of pbx_builtin_getvar_helper() that is not thread-safe. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@111909 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/doc/janitor-projects.txt b/doc/janitor-projects.txt index 9d89ef18ca..b111204f05 100644 --- a/doc/janitor-projects.txt +++ b/doc/janitor-projects.txt @@ -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) diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 1761a9bd7f..56bd83fa56 100644 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -800,6 +800,20 @@ int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **b /*! * \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);