Use thread-local storage to store pj_thread_descs.
authorMark Michelson <mmichelson@digium.com>
Mon, 20 Aug 2012 20:19:52 +0000 (20:19 +0000)
committerMark Michelson <mmichelson@digium.com>
Mon, 20 Aug 2012 20:19:52 +0000 (20:19 +0000)
commitdb69da3667955373c06ebae66141c3cd42834fcc
tree9ce9f5c3913b4042c61ddc68a936f1b1c255abe5
parenta2068c3db6ccec80b1a846150abf2812ba058a34
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

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371572 65c4cc65-6c06-0410-ace0-fbb531ad65f3
res/res_rtp_asterisk.c