[Kamailio-Users] freeing innername from htable Re: perl module, "pv_sprintf: Memory exhausted!"
Daniel-Constantin Mierla
miconda at gmail.com
Tue Jun 9 13:03:50 CEST 2009
Hello Christian,
On 06/09/2009 01:14 PM, Christian Koch wrote:
> Hello Daniel,
>
> Daniel-Constantin Mierla schrieb:
>> Do you call pv_parse_ht_name() from perl? If not, that function is
>> executed only at startup and it is not a cause for leaking. A clean
>> shutdown should free it, but there is not complete support for it
>> (some fixup functions have a free function, others done, as well as
>> the script actions tree).
> We're not calling this directly from perl, but it seems it is called
> automatically every time when accessing the pv $sht.
unfortunately you cannot use $sht in this way from perl module. The same
limitation that prevent calling any function from modules apply here --
the fixup system used at startup, when string parameters are
pre-compiled in different forms to speed up runtime execution.
It can be added as a feature request for future. For module functions I
added the core support for free fixup functions, but nobody committed to
continue the work in perl module.
If you want to work on it, I can assist and guide you.
Cheers,
Daniel
> We've modified ht_var.c from module htable for getting a backtrace
> every time memory is allocated in pv_parse_ht_name:
>
> void printBacktrace()
> {
> void *array[100];
> size_t size;
> char **strings;
> size_t i;
>
> size = backtrace (array, 100);
> strings = backtrace_symbols (array, size);
>
> LM_DBG("Obtained %zd stack frames.\n", size);
>
> for (i = 0; i < size; i++)
> LM_DBG("%s\n", strings[i]);
>
> free (strings);
> }
>
> int pv_parse_ht_name(pv_spec_p sp, str *in)
> {
> ht_pv_t *hpv=NULL;
> char *p;
> str pvs;
>
> if(in->s==NULL || in->len<=0)
> return -1;
>
> hpv = (ht_pv_t*)pkg_malloc(sizeof(ht_pv_t));
> if(hpv==NULL)
> return -1;
>
> LM_DBG("Allocated new memory %u/0x%x in
> pv_parse_ht_name()", hpv, hpv);
> printBacktrace();
> [...]
>
> When making a call we get the following outputs:
>
> xlog:
>
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:pv_parse_ht_name: Allocated new memory 136020048 in
> pv_parse_ht_name()
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: Obtained 10 stack frames.
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/htable.so(printBacktrace+0x2d)
> [0x1dd1c5]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/htable.so(pv_parse_ht_name+0x8f)
> [0x1dd8fe]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(pv_parse_spec+0x58f) [0x8082c35]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(pv_parse_format+0x1eb) [0x808409e]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: /usr/local/lib/kamailio/modules/xlog.so
> [0x1482c6]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: /usr/local/lib/kamailio/modules/xlog.so
> [0x148620]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: /usr/local/sbin/kamailio [0x808e68e]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: /usr/local/sbin/kamailio(fix_rls+0x12b)
> [0x8096892]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace: /usr/local/sbin/kamailio(main+0xcd)
> [0x8068215]
> May 29 16:56:01 AmbriaSip1 /usr/local/sbin/kamailio[27187]:
> DBG:htable:printBacktrace:
> /lib/tls/libc.so.6(__libc_start_main+0xd3) [0xb51df3]
>
>
> and perl:
>
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:pv_parse_ht_name: Allocated new memory
> 136017028/0x81b7484 in pv_parse_ht_name()
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace: Obtained 27 stack frames.
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/htable.so(printBacktrace+0x33)
> [0xf631cb]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/htable.so(pv_parse_ht_name+0x8f)
> [0xf63a42]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(pv_parse_spec+0x58f) [0x8082c35]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(pv_parse_format+0x1eb) [0x808409e]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/perl.so(pv_sprintf+0x93) [0x2a40c8]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/perl.so(XS_OpenSER__Message_pseudoVar+0x17f)
> [0x2a92f3]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so(Perl_pp_entersub+0x2ea)
> [0x813c
> b2]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so(Perl_runops_debug+0xba)
> [0x7f71
> 6d]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so
> [0x7a1b26]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so(Perl_call_sv+0x6d7)
> [0x7a7ef1]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so(Perl_call_pv+0x40)
> [0x7a81f9]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/perl.so(perl_exec2+0x198) [0x2af1c4]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/lib/kamailio/modules/perl.so(perl_exec1+0x2c) [0x2af69d]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(do_action+0x1401) [0x80531ed]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(run_action_list+0x28) [0x8055406]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(do_action+0x20ed) [0x8053ed9]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(run_action_list+0x28) [0x8055406]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(do_action+0x3199) [0x8054f85]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(run_action_list+0x28) [0x8055406]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(do_action+0x3199) [0x8054f85]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(run_action_list+0x28) [0x8055406]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(run_top_route+0x6d) [0x805570e]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(receive_msg+0x572) [0x8087934]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /usr/local/sbin/kamailio(udp_rcv_loop+0xd26) [0x80be5a6]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace: /usr/local/sbin/kamailio(main+0x3219)
> [0x806b361]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace:
> /lib/tls/libc.so.6(__libc_start_main+0xd3) [0xb51df3]
> Jun 2 10:53:28 AmbriaSip1 /usr/local/sbin/kamailio[19777]:
> DBG:htable:printBacktrace: /usr/local/sbin/kamailio [0x8051991]
>
> So because of this we don't think it is just called once but the
> allocated memory should be freed after processing a message.
>
>
>>
>> That structure is not freed because it used at runtime. During
>> startup, the name of $sht is parsed and kept as custom structure to
>> be used latter, for speed reasons.
>>
>> I tried to access the files you uploaded, with the log, but they
>> expired. If you have the one with memory debug, please send it to me.
> We still have it, but its 43MB (already zipped) and it's without the
> above "printBacktrace". If you need it anyway or need a complete
> logfile including the backtrace we could send it to you.
>
> Thanks for your help,
> Christian
> ------------------------------------------------------------------------
>
> _______________________________________________
> Kamailio (OpenSER) - Users mailing list
> Users at lists.kamailio.org
> http://lists.kamailio.org/cgi-bin/mailman/listinfo/users
> http://lists.openser-project.org/cgi-bin/mailman/listinfo/users
--
Daniel-Constantin Mierla
http://www.asipto.com/
More information about the Users
mailing list