[Kamailio-Devel] Out of pkg mem with own module

Schumann Sebastian Sebastian.Schumann at t-com.sk
Mon Nov 10 09:49:48 CET 2008


Hi all
 
I have written a module and after running the proxy for quite some time I get out of pkg mem message.
 
I attached a piece of code how I deal with pkg mem. Please let me know if there is something wrong or forgotten respectively.
 
Thanks a lot.
Sebastian
 
[snip]
n = body_start.len + pres_uri.len + body_middle.len + TUPLE_ID_SIZE + body_end.len;
s = (char *)pkg_malloc(n); /* as pointers are used must not be freed after last use of any reference */
if(s==NULL) {
    LM_ERR("no more pkg mem for body (%d)\n", n);
    return -1;
}

p=s;
memcpy(p, body_start.s, body_start.len);
p += body_start.len;
memcpy(p, pres_uri.s, pres_uri.len);
p += pres_uri.len;
memcpy(p, body_middle.s, body_middle.len);
p += body_middle.len;

int i;
for(i=0;i<TUPLE_ID_SIZE;i++) {
    *(p++) = tuple[i];
}

memcpy(p, body_end.s, body_end.len);
p += body_end.len;
body.s = s;
body.len = (int)(p-s);

if(body.len > n) {
    LM_ERR("Buffer size overflow for body\n");
    pkg_free(s);
    return -1;
}
...
pkg_free(s);
[snip]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kamailio.org/pipermail/devel/attachments/20081110/103132f2/attachment.htm 


More information about the Devel mailing list