[OpenSIPS-Devel] Out of pkg mem with own module
Bogdan-Andrei Iancu
bogdan at voice-system.ro
Mon Nov 10 17:51:56 CET 2008
Hi Sebastian,
The snip looks ok - are you sure the leak comes from here? have you
tried to use the memory debuger to identify the source -
http://www.opensips.org/index.php?n=Resources.DocsTsMem
Regards,
Bogdan
Schumann Sebastian wrote:
> 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]
> ------------------------------------------------------------------------
>
> _______________________________________________
> Devel mailing list
> Devel at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
>
More information about the Devel
mailing list