On 11/9/06, Diego Betancor <[EMAIL PROTECTED]> wrote:
> I am very confused with who manages the memory, Sofia?, the aplication?.

Both. Unfortunately the memory management is inconsistent. In some
cases, we have reference counting, in some cases the application is
responsible for destroying the objects, sometimes the stack just marks
the object as destroyed and releases its storage when appropriate.

> case 1. With a dialog finishes with a BYE or CANCEL who destroys the leg,
> Does the application have to destroy it or Sofia destroys (an liberates
> memory I presume) it automaticaly?.

Unfortunately, the dialog management with SIP is rather hairy. BYE (or
an error response to the initial INVITE, not CANCEL itself) destroys
the dialog usage, not the dialog. Here is a draft with some additional
information about SIP dialogs and when they are considered destroyed,
etc:

http://www.ietf.org/internet-drafts/draft-ietf-sipping-dialogusage-04.txt

In nta it is left entirely to application to decide when the dialog is
destroyed and therefore your application has to explicitly call
nta_leg_destroy().

> case 2. URLs and many more thing in which you need to give to the function
> your home. Case in point is the function url_as_string().
>
> in
> printf("The url is %s", url_as_string(home, url));
>
> I am just leaking memory?

That depends on your home. It is possible to use a temporary home that
lives for the duration of the function and is destroyed before
returning from the function, like

su_home_t home[1] = { SU_HOME_INIT(home) };

printf("The url is %s", url_as_string(home, url));

su_home_deinit(home);

In this particular case, there are macros URL_PRINT_FORMAT and
URL_PRINT_ARGS() that you could use (but in the expense of your
application size):

printf("The url is " URL_PRINT_FORMAT, URL_PRINT_ARGS(url));

>and should be:
> char *ch
> ch = url_as_string(home, url);
> printf("The url is %s", ch);
> free(home, ch);

You have to use su_free() if you have non-NULL home:

char *ch
ch = url_as_string(home, url);
printf("The url is %s", ch);
su_free(home, ch);

> Same thing with make_url(home, "<sip....>);
>
> the question is I guess, I am responsible to free the memory that was
> allocated by a Sofia funtion, even if I didn't make the allocation?

That is right. The memory home is there to help with that task, so
that you could have a home that is alive while your allocations are
relevant. When the home is released all the associated memory areas
would be freed.

-- 
Pekka.Pessi mail at nokia.com

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to