<p>Hello Chevio.</p><p></p><p>Just to be sure, perform the corresponding casts when assgining. For example<br></p><p>...</p><p> strsql=(char*)pkg_malloc(100);</p><p>After calling pkg_malloc, you should evaluate the return value; it returns NULL if memory allocation could not be performed. That would be a way to determine whether you exhausted memory.</p>
<p>Best regards.</p><p>Sergio.</p><br><div class="gmail_quote">On Wed, Mar 11, 2009 at 5:10 PM, Chevio <span dir="ltr"><<a href="mailto:emercado@rapidlink.com">emercado@rapidlink.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hi, All,<br>
<br>
I am getting a segmentation fault when calling pkg_malloc from a custom<br>
module in opensips 1.4.4 notls,<br>
<br>
here is the offending code :<br>
<br>
int tncgw_ip_lookup(struct sip_msg* msg, char* _para1, char* _para2)<br>
{<br>
<br>
str _user_ip;<br>
db_res_t* db_res = NULL;<br>
char* strsql=NULL;<br>
char* to_prefix=NULL;<br>
char* new_uri=NULL;<br>
char* new_to=NULL;<br>
str strsqlstr;<br>
str techprefix;<br>
str to;<br>
int retval=-1;<br>
int dbg=1;<br>
<br>
if(dbg)LM_INFO("TNCGW ip_address_lookup 2009.03.11.a beta\n");<br>
<br>
techprefix.s=NULL;<br>
_user_ip.s=NULL;<br>
<br>
if(dbg) LM_INFO("---Memory allocation\n");<br>
<br>
strsql=pkg_malloc(100);<br>
new_to=pkg_malloc(MAX_URI_SIZE); ## this is the line 97<br>
new_uri=pkg_malloc(MAX_URI_SIZE);<br>
to_prefix=pkg_malloc(8);<br>
<br>
<br>
and here is the back trace<br>
<br>
Program terminated with signal 11, Segmentation fault.<br>
[New process 32735]<br>
#0 fm_malloc (qm=0x8183b00, size=<value optimized out>) at<br>
mem/f_malloc.c:125<br>
125 if (frag->size <= (*f)->size) break;<br>
(gdb) bt<br>
#0 fm_malloc (qm=0x8183b00, size=<value optimized out>) at<br>
mem/f_malloc.c:125<br>
#1 0xb7ab0873 in tncgw_ip_lookup (msg=0x8196ed8, _para1=0x0, _para2=0x0) at<br>
tncgw.c:97<br>
#2 0x08055275 in do_action (a=0x818d278, msg=0x8196ed8) at action.c:845<br>
#3 0x08054172 in run_action_list (a=0x818d278, msg=0x8196ed8) at<br>
action.c:138<br>
#4 0x080a0516 in eval_expr (e=0x818d2e0, msg=0x8196ed8, val=0xbf8d4ef8) at<br>
route.c:1133<br>
#5 0x08053e2f in do_assign (msg=0x8196ed8, a=0x818d308) at action.c:207<br>
#6 0x080549f5 in do_action (a=0x818d308, msg=0x8196ed8) at action.c:951<br>
#7 0x08054172 in run_action_list (a=0x818d308, msg=0x8196ed8) at<br>
action.c:138<br>
#8 0x08056845 in do_action (a=0x818d8c0, msg=0x8196ed8) at action.c:717<br>
#9 0x08054172 in run_action_list (a=0x8189fd0, msg=0x8196ed8) at<br>
action.c:138<br>
#10 0x080577f4 in run_top_route (a=0x8189fd0, msg=0x8196ed8) at action.c:118<br>
<br>
does it mean I ran out of memory? if that is the case pkg_malloc should<br>
return a 0 instead of crashing.<br>
<br>
I will appreciate any help.<br>
<br>
Chevio<br>
--<br>
View this message in context: <a href="http://n2.nabble.com/segmentation-fault-when-calling-pkg_malloc-tp2463853p2463853.html" target="_blank">http://n2.nabble.com/segmentation-fault-when-calling-pkg_malloc-tp2463853p2463853.html</a><br>
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Sergio Gutiérrez<br>