[reSIProcate] Memory leak when creating the SDP from string

Scott Godin sgodin at sipspectrum.com
Mon Nov 12 08:46:07 CST 2018


Hi Diego,

Many resip classes will try to use memory as efficiently as possible, by
avoiding data copies.  If the a SIP message block received off the wire is
stored in it's entirety, then the objects that attach to it to provide
parsing, endeavor to avoid creating copies of all the header bytes, or body
byte as they are parsed.   So what is expected in your examples is the the
original Data block you provided stays around for as long as the resulting
Pidf contents class.  If the Data goes away and the Pidf class sticks
around longer, then it will core.

In your case, you really want HeaderFieldValue to take ownership of the
Data or to copy it and own it.  There is no interface to have
HeaderFieldValue take ownership of a Data object, so....

Looking at the HeaderFieldValue class, seems like the easiest thing to use
would be the init method, which allows you to specify if it should own the
data or not.  I haven't tested this, but give it a go....

  Data text(publishBody);

   HeaderFieldValue hfv;

   hfv.init(text.data(), text.size(), true /* own? */);

   Mime type("application", "pidf+xml");

   Pidf pc(hfv, type);

   boost::shared_ptr<resip::Contents> body(&pc);


Scott






On Fri, Nov 9, 2018 at 1:31 PM Diego Carvalho Domingos <ddomingos at daitan.com>
wrote:

> Recently I found that my code has a leak when creating the SDP from
> string. I tried to find the correct way of doing this in examples/tests but
> could not understand who is responsible to delete the Data pointer. For
> instance, I found this:
>
> /*
>
>    WHAT PREVIOUSLY WORKED BUT NOW CORES...
>
>    Data text(publishBody);
>
>    HeaderFieldValue hfv(text.data(), text.size());
>
>    Mime type("application", "pidf+xml");
>
>    Pidf pc(&hfv, type);
>
>    boost::shared_ptr<resip::Contents> body(&pc);
>
>
>
>    ....
>
>    WHAT NOW NEEDS TO BE DONE INSTEAD..
>
>    */
>
>    Data* text = new Data(publishBody);
>
>    HeaderFieldValue hfv(text->data(), text->size());
>
>    Mime type("application", "pidf+xml");
>
>    Pidf* pc = new Pidf(hfv, type);
>
>    boost::shared_ptr<resip::Pidf> body(pc);
>
>    /*
>
>    *
>
> */ *Is this the correct way? If so, who deletes the data in this code? I
> could not find in either HeaderFieldValue (in the constructor that takes a
> char * and size, mMine is set to false) nor in Contents (in my case
> SdpContents).
> Another example, which is very similar to my case, is the generateBody in
> this example (I believe it is no longer in the current code base):
> http://svn.resiprocate.org/dox/dum/testSMIMEInvite_8cxx_source.html#l00232
> I did not test but I guess there is a leak in this example as well. Who
> deletes the pointer returned by generateBody and who deletes the Data *
> created inside the method?
>
> I appreciate any help. Thanks in advance. Att,
>
> Diego Domingos
> _______________________________________________
> resiprocate-devel mailing list
> resiprocate-devel at resiprocate.org
> https://list.resiprocate.org/mailman/listinfo/resiprocate-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20181112/a3fa465a/attachment.htm>


More information about the resiprocate-devel mailing list