[Freeswitch-dev] Memory Leak Patch

Michael Jerris mike at jerris.com
Thu May 22 16:16:42 MSD 2014


Its possible you are getting this only for failed calls?  You should probably be doing this out of i_state in nua_callstate_terminated, not explicitly off the bye.

On May 21, 2014, at 11:40 PM, Jerry Richards <jerry.richards at teotech.com> wrote:

> Hmmm, yes we are calling nua_handle_destroy() after receiving the nua_i_bye event (if the far-end hangs up first) or also after receiving the nua_r_bye event (if the local user hangs up first).  I don't know of anything else that needs to be invoked at the end of a call?
> 
> -----Original Message-----
> From: freeswitch-dev-bounces at lists.freeswitch.org [mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of Michael Jerris
> Sent: Wednesday, May 21, 2014 3:48 PM
> To: freeswitch-dev at lists.freeswitch.org
> Subject: Re: [Freeswitch-dev] Memory Leak Patch
> 
> Needing this patch seems incredibly strange, are you sure your properly destroying the nh at the end of your call?
> 
> On May 21, 2014, at 10:32 PM, Jerry Richards <jerry.richards at teotech.com> wrote:
> 
>> No, this is related to just an ordinary call without 100rel.  Yes, it is the memory allocated to store the "100 Trying" message, which is received after sending an INVITE.  And as I mentioned, we observed this in our phone implementation, which uses the old sofia-sip version 1.12.11 version.  I was just notifying the mailing list in case this might also be an issue for Freeswitch.  I know the Freeswitch sofia-sip has a lot changes since the 1.12.11 sofia-sip version, so maybe you guys already accounted for this memory deallocation?
>> 
>> -----Original Message-----
>> From: freeswitch-dev-bounces at lists.freeswitch.org 
>> [mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of 
>> Michael Jerris
>> Sent: Wednesday, May 21, 2014 2:43 PM
>> To: freeswitch-dev at lists.freeswitch.org
>> Subject: Re: [Freeswitch-dev] Memory Leak Patch
>> 
>> thats strange, was this only when 100rel was turned on?  I'm sure we would have noticed this if it was happening.  I don't get totally what memory you are talking about, are you talking about the 100 trying we received?
>> 
>> On May 21, 2014, at 9:25 PM, Jerry Richards <jerry.richards at teotech.com> wrote:
>> 
>>> What we know for sure is, the memory allocated for "100 Trying" replies to outbound INVITE requests was simply not getting freed.  "original->orq_timeout" seemed a convenient variable to trigger freeing this memory since it goes to zero about 25-30 seconds after the call is disconnected.  Without this patch, we were losing about 3 kilobytes per outbound call.
>>> 
>>> -----Original Message-----
>>> From: freeswitch-dev-bounces at lists.freeswitch.org
>>> [mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of 
>>> Michael Jerris
>>> Sent: Wednesday, May 21, 2014 1:59 PM
>>> To: freeswitch-dev at lists.freeswitch.org
>>> Subject: Re: [Freeswitch-dev] Memory Leak Patch
>>> 
>>> So correct me if I'm wrong, this looks like leak on timeout on provisional reply?  I don't think we have this one fixed...
>>> 
>>> On May 21, 2014, at 8:49 PM, Jerry Richards <jerry.richards at teotech.com> wrote:
>>> 
>>>> Here is the patch made to the latest (today's) Freeswitch stable branch (did you fix this leak in a differently somewhere else?):
>>>> 
>>>> *** C:\work\SipBugs\Phone\MemoryLeak\fs_stable\nta_ORIGINAL.c
>>>> 2014-02-20 18:43:27.000000000 -0700
>>>> --- C:\work\SipBugs\Phone\MemoryLeak\fs_stable\nta_PATCHED.c
>>>> 2014-05-21 12:14:39.000000000 -0700
>>>> ***************
>>>> *** 9166,9175 ****
>>>> --- 9166,9187 ----
>>>> }
>>>> 
>>>> return orq;
>>>> }
>>>> 
>>>> /** destroy msg if no timeout set on receive outgoing */
>>>> + int check_outgoing_recv_timeout(nta_outgoing_t *original, msg_t
>>>> + *msg) {
>>>> + 	SU_DEBUG_5(("nta %s: orq_timeout=%d.\n","check_outgoing_recv_timeout",original->orq_timeout));
>>>> +     if(original->orq_timeout==0){          
>>>> +         outgoing_remove(original);
>>>> +         msg_destroy(msg);            
>>>> +         return 0;            
>>>> +     }
>>>> +     return original->orq_timeout;
>>>> + }
>>>> 
>>>> /** Process a response message. */
>>>> int outgoing_recv(nta_outgoing_t *_orq,
>>>> 		  int status,
>>>> 		  msg_t *msg,
>>>> 		  sip_t *sip)
>>>> ***************
>>>> *** 9232,9248 ****
>>>> --- 9244,9264 ----
>>>> 	original->orq_status = status;
>>>>     if (orq->orq_status < 200)
>>>> 	orq->orq_status = status;
>>>> 
>>>>     if (original->orq_queue == sa->sa_out.inv_calling) {
>>>> 		outgoing_queue(sa->sa_out.inv_proceeding, original);
>>>> + 		 if(check_outgoing_recv_timeout(original,msg)==0)
>>>> + 			return 0;
>>>>     }
>>>>     else if (original->orq_queue == sa->sa_out.inv_proceeding) {
>>>> 		if (sa->sa_out.inv_proceeding->q_timeout) {
>>>> 			outgoing_remove(original);
>>>> 			outgoing_queue(sa->sa_out.inv_proceeding, original);
>>>> + 			if(check_outgoing_recv_timeout(original,msg)==0)
>>>> + 				return 0;				
>>>> 		}
>>>>     }
>>>> 
>>>>     /* Handle 100rel */
>>>>     if (sip && sip->sip_rseq) {
>>>> 	if (outgoing_recv_reliable(orq, msg, sip) < 0) {
>>>> 
>>>> 
>>>> Here is the patch made to the latest (today's) Freeswitch master branch (did you fix this leak in a differently somewhere else?):
>>>> 
>>>> *** C:\work\SipBugs\Phone\MemoryLeak\fs_master\nta_ORIGINAL.c
>>>> 2014-02-20 18:45:34.000000000 -0700
>>>> --- C:\work\SipBugs\Phone\MemoryLeak\fs_master\nta_PATCHED.c
>>>> 2014-05-21 12:17:54.000000000 -0700
>>>> ***************
>>>> *** 9307,9316 ****
>>>> --- 9307,9328 ----
>>>> }
>>>> 
>>>> return orq;
>>>> }
>>>> 
>>>> /** destroy msg if no timeout set on receive outgoing */
>>>> + int check_outgoing_recv_timeout(nta_outgoing_t *original, msg_t
>>>> + *msg) {
>>>> + 	SU_DEBUG_5(("nta %s: orq_timeout=%d.\n","check_outgoing_recv_timeout",original->orq_timeout));
>>>> +     if(original->orq_timeout==0){          
>>>> +         outgoing_remove(original);
>>>> +         msg_destroy(msg);            
>>>> +         return 0;            
>>>> +     }
>>>> +     return original->orq_timeout;
>>>> + }
>>>> 
>>>> /** Process a response message. */
>>>> int outgoing_recv(nta_outgoing_t *_orq,
>>>> 		  int status,
>>>> 		  msg_t *msg,
>>>> 		  sip_t *sip)
>>>> ***************
>>>> *** 9373,9389 ****
>>>> --- 9385,9405 ----
>>>> 	original->orq_status = status;
>>>>     if (orq->orq_status < 200)
>>>> 	orq->orq_status = status;
>>>> 
>>>>     if (original->orq_queue == sa->sa_out.inv_calling) {
>>>> 		outgoing_queue(sa->sa_out.inv_proceeding, original);
>>>> + 		 if(check_outgoing_recv_timeout(original,msg)==0)
>>>> + 			return 0;
>>>>     }
>>>>     else if (original->orq_queue == sa->sa_out.inv_proceeding) {
>>>> 		if (sa->sa_out.inv_proceeding->q_timeout) {
>>>> 			outgoing_remove(original);
>>>> 			outgoing_queue(sa->sa_out.inv_proceeding, original);
>>>> + 			if(check_outgoing_recv_timeout(original,msg)==0)
>>>> + 				return 0;				
>>>> 		}
>>>>     }
>>>> 
>>>>     /* Handle 100rel */
>>>>     if (sip && sip->sip_rseq) {
>>>> 	if (outgoing_recv_reliable(orq, msg, sip) < 0) {
>>>> 
>>>> I realized the mailing list does not accept attachments, so I put the patches in-line here.
>>>> 
>>>> Jerry
>>>> 
>>>> -----Original Message-----
>>>> From: freeswitch-dev-bounces at lists.freeswitch.org
>>>> [mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of 
>>>> Ken Rice
>>>> Sent: Wednesday, May 21, 2014 1:37 PM
>>>> To: freeswitch-dev at lists.freeswitch.org
>>>> Subject: Re: [Freeswitch-dev] Memory Leak Patch
>>>> 
>>>> You should really check the lastest version... I believe those were patched ages ago...
>>>> 
>>>> 
>>>> On 5/21/14 3:29 PM, "Jerry Richards" <jerry.richards at teotech.com> wrote:
>>>> 
>>>>> We patched sofia-sip version 1.12.11 for memory leaks we found in sofia-sip.
>>>>> It's related to memory allocated for provisional replies to 
>>>>> outbound INVITE transactions which never get freed.  I suspect 
>>>>> Freeswitch has the same issue, so I created a patch file (attached) 
>>>>> for each of the latest (as of today) 
>>>>> libs/sofia-sip/libsofia-sip-ua/nta/nta.c file in both the stable and master Freeswitch branches.
>>>>> 
>>>>> Do you think you can use these patches in Freeswitch?  Or do you 
>>>>> think you already fixed these memory leaks in a different way?
>>>>> 
>>>>> Best Regards,
>>>>> Jerry



Join us at ClueCon 2013 Aug 6-8, 2013
More information about the FreeSWITCH-dev mailing list