Metaswitch/sprout — pull request #30 by kswmsw (2013-05-22 13:33:58+00:00)
Title: [Reviewer: Mike] Track lifetime of AsChain objects more precisely.

Hi Mike - please could you review. I'm currently running VG over it to check we haven't introduced any leaks; I'll merge once that's done.

Fixes a race where one thread could look up the AsChain in the AsChainTable and
start using it, while another thread could could destroy the initial
UASTransaction, destroying the AsChain. Fix is to use reference counting
to ensure the AsChain isn't destroyed until no thread is using it.

Clearly document the life cycle of AsChain at the top of AsChain's declaration.

Hide almost all methods of AsChain itself, so caller must use AsChainLink.
That makes AsChainLink a reference-holder for AsChain. I wasn't quite brave
enough to use RAII here (given the amount of copying of AsChainLink that
goes on), so there's an explicit release() method.

Separate removal from the map (request_destroy()) from deleting the AsChain
object (which happens within dec_ref()).

Explain the lifetime of an AsChain object (and an ODI token).

Thanks!

--KW 8-)