< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

Re: [reSIProcate] Problem with memory corruption


Quoting Cullen Jennings <fluffy@xxxxxxxxx>:

'Borrow' means that the Data instance MAY write to the buffer and MUST NOT
delete the buffer.

'Share' means that the Data instance MUST NOT write to the buffer and MUST NOT
delete the buffer.

'Take' means that the Data instance MAY write to the buffer and MUST delete the
buffer.

'Share' is what we use to create a Data instance whose buffer overlays someone
else's memory -- like a SipMessage.

In the case below I would guess that you do not intend to write to the Data in
question, so Share may be a bit more appropriate, but Borrow will solve your
double delete issue.

david

> 
> Thanks - that did work so I checked it in.
> 
> The more I look at the Security.cxx code, there looks there are still a fair
> number of bugs with it.
> 
> 
> On 11/26/04 7:21 PM, "nagendra modadugu" <nagendra@xxxxxxxxxxxxxxx> wrote:
> 
> > 
> > This fix works for me:
> > 
> > --- Security.cxx        (revision 3639)
> > +++ Security.cxx        (working copy)
> > @@ -425,7 +425,7 @@
> >           size_t len = BIO_get_mem_data(out,&p);
> >           assert(p);
> >           assert(len);
> > -         Data  buf(Data::Take, p, len);
> > +         Data  buf(Data::Borrow, p, len);
> >           
> >           this->onWritePEM(key, type, buf);
> >        }
> > 
> > My guess is that Data::Take results in a change of ownership
> > of a buffer that is _also_ owned by the memory BIO.
> > 
> > So this buffer gets deleted twice: first when the Data object
> > goes out of scope, and second when the BIO structure is freed.
> > I don't know what distinction, if any, exists between Data::Share
> > and Data::Borrow.
> > 
> > nagendra
> > 
> > ps:  I don't have commit access, so if this fix makes sense and
> > works for you please commit.
> > 
> > * Cullen Jennings <fluffy@xxxxxxxxx> [2004-11-26 16:37:20 -0800]:
> > 
> >> 
> >> I'm having some problems that I think are partially caused by a buffer
> >> getting freed twice and mostly cause by me not understanding how Data
> works.
> >> 
> >> What is the Take, Share, Borrow stuff mean in Data?
> >> 
> >> If I have a buffer and I want the Data to make a copy of the buffer in
> the
> >> constructor then never touch the buffer again including not freeing it,
> What
> >> do I do?
> >> 
> >> Thanks, Cullen
> >> 
> >> 
> >> _______________________________________________
> >> resiprocate-devel mailing list
> >> resiprocate-devel@xxxxxxxxxxxxxxxxxxx
> >> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
> 
> 
> _______________________________________________
> resiprocate-devel mailing list
> resiprocate-devel@xxxxxxxxxxxxxxxxxxx
> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
>