Summary:ASTERISK-10264: memory leak due to ast_cdr_alloc invocations during call routing
Reporter:under (under)Labels:
Date Opened:2007-09-10 02:33:26Date Closed:2007-09-10 09:49:13
Versions:Frequency of
Environment:Attachments:( 0) show_memory_summary.txt
Description:After approx. 600000 bridged calls asterisk grows up to 512Mb and OS (Freebsd) forbids further memory allocations. Due to that asterisk process dies.
Following scheme was used to produce the error situation:
1)sipp call originator(sipp -sn uac_pcap -p 5062 -s XXX
2)sipp call terminator(sipp  -sn uas -p 5061)
3)asterisk config in 'additional information' section.
After problem detection asterisk was built with MALLOC_DEBUG. Further investigation showed increasing memory allocations in cdr.c(ast_cdr_alloc). After that following lines have been inserted in cdr.c:

--- cdr.c.orig  Mon Sep 10 10:47:05 2007
+++ cdr.c       Mon Sep 10 10:27:22 2007
@@ -437,6 +437,7 @@

               ast_cdr_free_vars(cdr, 0);
+               ast_log(LOG_NOTICE, "Freed cdr %i\n", cdr);
               cdr = next;
@@ -456,6 +457,7 @@
struct ast_cdr *ast_cdr_alloc(void)
       struct ast_cdr *x = ast_calloc(1, sizeof(struct ast_cdr));
+       ast_log(LOG_NOTICE, "Allocated cdr %i\n", x);
       if (!x)
               ast_log(LOG_ERROR,"Allocation Failure for a CDR!\n");
       return x;

After that in asterisk log whole call bridging look like this:

[Sep 10 10:31:05] NOTICE[30228]: cdr.c:460 ast_cdr_alloc: Allocated cdr 135926784
   -- Executing [380972400426@customer:1] Dial("SIP/5063-081ac000", "SIP/sipp-server/380972400426") in new stack
[Sep 10 10:31:05] NOTICE[30228]: cdr.c:460 ast_cdr_alloc: Allocated cdr 136064000
   -- Called sipp-server/380972400426
   -- SIP/sipp-server-081c7000 is ringing
   -- SIP/sipp-server-081c7000 answered SIP/5063-081ac000
   -- Native bridging SIP/5063-081ac000 and SIP/sipp-server-081c7000
[Sep 10 10:31:06] WARNING[30228]: channel.c:2605 ast_indicate_data: Unable to handle indication 3 for 'SIP/5063-081ac000'
   -- Native bridging SIP/5063-081ac000 and SIP/sipp-server-081c7000
[Sep 10 10:31:06] NOTICE[30228]: cdr.c:460 ast_cdr_alloc: Allocated cdr 136054784
 == Spawn extension (customer, 380972400426, 1) exited non-zero on 'SIP/5063-081ac000'
[Sep 10 10:31:06] NOTICE[30228]: cdr.c:440 ast_cdr_free: Freed cdr 136054784

3 memory allocations with 1 memory releasing obviously leeds to memory leak.



exten => _X.,1,Dial(SIP/sipp-server/222)
Comments:By: under (under) 2007-09-10 02:41:55

Last log was gathered when calling with linphone to ease log parsing. Situation will be the same when calling with sipp.

By: under (under) 2007-09-10 04:49:54

Attached file with show memory summary output at the time when asterisk occupied 373MB of memory

By: Andrey Solovyev (corruptor) 2007-09-10 04:54:17

Maybe this is related to http://bugs.digium.com/view.php?id=10658 ?
I also had memory leak but after applying that patch it's gone.

By: under (under) 2007-09-10 05:55:53

corruptor, thank you very much.
Problem really resolved.
I never thought it is related to res_features.c...
Strange, that issue was resolved 4 months ago but it's not in 1.4.11 release

By: Jason Parker (jparker) 2007-09-10 09:49:12

Closing.  Duplicate of 10658.

ASTERISK-10247 was closed 4 days ago - not 4 months ago...