Metaswitch/sprout — pull request #598 by mike-evans (2014-06-10 09:44:26+00:00)
Title: [Reviewer Andy] #597 fix memory leaks

Andy

Welcome back! Can you review my fix to a couple of memory leaks (covered by issue #597).

The first is a legacy of the changes to support delayed 100 Trying responses, where the code was cloning the original pjsip_rx_data so it could build the response later, and in some error/overload cases, this seemed to be leaked. I didn't identify the exact repro scenario, but instead decided there was a better way to implement the function - so I changed it to remove the cloning of the pjsip_rx_data and to build the 100 Trying if required by cloning the _best_rsp pjsip_tx_data constructed when the transaction was first set up. There was already code to do this in the send_response method only. This both reduces occupancy and increases performance as well as getting rid of the leak.

The second seems to be a pjsip_tx_data reference counting problem when we fail to retry a request - the code was incrementing the reference count on the pjsip_tx_data prior to doing the retry, but not decrementing the reference count if the send failed. I verified in the PJSIP code that it only decrements the reference count if the send is successful.

I've tested both fixes live (and run the existing UTs over them).

Mike