You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Nikolay Ognyanov (JIRA)" <xe...@xml.apache.org> on 2005/03/16 16:07:21 UTC
[jira] Created: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
wrong string destruction in MemBufInputSource::~MemBufInputSource()
-------------------------------------------------------------------
Key: XERCESC-1378
URL: http://issues.apache.org/jira/browse/XERCESC-1378
Project: Xerces-C++
Type: Bug
Components: SAX/SAX2
Versions: 2.6.0
Environment: Any
Reporter: Nikolay Ognyanov
MemBufInputSource::~MemBufInputSource()
{
if (fAdopted)
delete [] (XMLByte*)fSrcBytes;
}
This seems terribly wrong. Constructor initializes fSrcBytes
with its argument srcDocBytes and this never changes, so the
original argument string is deleted here and not a copy of it.
Actual creation and destruction of a copy if fAdopted is set
is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
above should be removed from the destructor and it should do
nothing.
Regards
Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Nikolay Ognyanov (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_61100 ]
Nikolay Ognyanov commented on XERCESC-1378:
-------------------------------------------
I think I understand now where the confusion came
from. I respect your position even though I do not
share it but if this is the intended use of adoptBufer
then at least documentation should be fixed because it
clearly claims something quite different. Here is a
quote from API documentation for MemBufInputSource:
adoptBuffer Indicates whether this object should
adopt the buffer (i.e. make a copy of it)
or just use it in place.
This is exactly what caused segfaults in our code -
a coder (after looking at the documentation) believed
that the class creates and destroys a copy of the
buffer if adoptBuffer is true and so did delete the
buffer for a second time. Rippples of this went
through several levels of method invocations and data
structures and thus became "magic" and ended up with
a more paranoid person (myself) chasing the issue
down to the source of MemBufInputSource.
BTW - Xerces C++ is a great product and we value it
very much. So thank you.
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Gareth Reakes (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_60978 ]
Gareth Reakes commented on XERCESC-1378:
----------------------------------------
Hi,
My reading of the code is slightly different. BinMemInputStream does not delete if fAdopted is set, but rather if fCopyBufToStream is set to true. If it is true, then BinMemInputStream makes a copy in the constructor and therefore should delete it. Since MemBufInputSource has its own copy, if fAdopted is set it also deletes it. Do you agree?
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Closed: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Gareth Reakes (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=history ]
Gareth Reakes closed XERCESC-1378:
----------------------------------
Resolution: Fixed
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Nikolay Ognyanov (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_61105 ]
Nikolay Ognyanov commented on XERCESC-1378:
-------------------------------------------
Thanks!
Regards
Nikolay
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: [jira] Commented: (XERCESC-1378) wrong string destruction in
MemBufInputSource::~MemBufInputSource()
Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Opps, sorry everyone, forgot to add it to the bug.
Cheers,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: [jira] Commented: (XERCESC-1378) wrong string destruction in
MemBufInputSource::~MemBufInputSource()
Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hey,
Nikolay Ognyanov (JIRA) wrote:
> [ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_60981 ]
>
> Nikolay Ognyanov commented on XERCESC-1378:
> -------------------------------------------
>
> I agree with the part about BinMemInputStream.
>
> I disagree however about the local copy in MemBufInputSource. I see no creation of such
> copy anywhere in MemBufInputSource.cpp. Apart
> from the destructor fSrcBytes appears only
> in the 2 constructors like this :
Exactly, no copy is created. However, MembufInputSource offers the
facility to delete the string you passed in via the adoptBuffer
parameter. If you set it to true then it will take care of deleting it
for you. That way, if you newed the string in the calling class you no
longer have to care about it.
> MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes
> , const unsigned int byteCount
> , const XMLCh* const bufId
> , const bool adoptBuffer
> , MemoryManager* const manager) :
> InputSource(bufId, manager)
> , fAdopted(adoptBuffer)
> , fByteCount(byteCount)
> , fCopyBufToStream(true)
> , fSrcBytes(srcDocBytes)
> {
> }
>
> Since srcDocBytes and fSrcBytes are pointers this initialization creates
> copy of the pointer (srcDocBytes) and not copy of the content it points to. If this was nor true BTW then it would be wrong again because copy would be created unconditionally regardlis of the value of fAdopted.
>
> Another way to easily verify how wrong things are here
> is to search in MemBufInputSource.cpp for fAdopted.
> Then you will see that it only appears in initialization and in the destruction conditional I quoted. This can not be true because creation of a copy of the arg string is supposed to depend on it.
No, the creation of a copy is not dependent on the flag - just whether
the class should delete it. Having a parameter like this can tidy up
calling code and offer possible optimizations (you only have to create 1
copy of the string). You will find this used in a fair few places in xerces.
>
> BTW - I found out this issue out not by mere code
> inspection but the hard way after debugging some
> "magic" segfaults...
I hate those :) I never say never, but I don't think this is the issue.
The only way I can see this happening is if you call
1) Make a MemBufInputSource with adopt set to true
2) call MemBufInputSource::setCopyBufToStream(false)
3) call makeStream()
4) delete the MemBufInputSource
5) do something with the BinMemInoutStream returned from makeStream
If you do that then it will break.
Regards,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Nikolay Ognyanov (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_60981 ]
Nikolay Ognyanov commented on XERCESC-1378:
-------------------------------------------
I agree with the part about BinMemInputStream.
I disagree however about the local copy in MemBufInputSource. I see no creation of such
copy anywhere in MemBufInputSource.cpp. Apart
from the destructor fSrcBytes appears only
in the 2 constructors like this :
MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes
, const unsigned int byteCount
, const XMLCh* const bufId
, const bool adoptBuffer
, MemoryManager* const manager) :
InputSource(bufId, manager)
, fAdopted(adoptBuffer)
, fByteCount(byteCount)
, fCopyBufToStream(true)
, fSrcBytes(srcDocBytes)
{
}
Since srcDocBytes and fSrcBytes are pointers this initialization creates
copy of the pointer (srcDocBytes) and not copy of the content it points to. If this was nor true BTW then it would be wrong again because copy would be created unconditionally regardlis of the value of fAdopted.
Another way to easily verify how wrong things are here
is to search in MemBufInputSource.cpp for fAdopted.
Then you will see that it only appears in initialization and in the destruction conditional I quoted. This can not be true because creation of a copy of the arg string is supposed to depend on it.
BTW - I found out this issue out not by mere code
inspection but the hard way after debugging some
"magic" segfaults...
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Gareth Reakes (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_60986 ]
Gareth Reakes commented on XERCESC-1378:
----------------------------------------
Hey,
Nikolay Ognyanov (JIRA) wrote:
> [ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_60981 ]
> Nikolay Ognyanov commented on XERCESC-1378:
> -------------------------------------------
>
> I agree with the part about BinMemInputStream.
>
> I disagree however about the local copy in MemBufInputSource. I see no creation of such
> copy anywhere in MemBufInputSource.cpp. Apart
> from the destructor fSrcBytes appears only
> in the 2 constructors like this :
Exactly, no copy is created. However, MembufInputSource offers the facility to delete the string you passed in via the adoptBuffer parameter. If you set it to true then it will take care of deleting it for you. That way, if you newed the string in the calling class you no longer have to care about it.
> MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes
> , const unsigned int byteCount
> , const XMLCh* const bufId
> , const bool adoptBuffer
> , MemoryManager* const manager) :
> InputSource(bufId, manager)
> , fAdopted(adoptBuffer)
> , fByteCount(byteCount)
> , fCopyBufToStream(true)
> , fSrcBytes(srcDocBytes)
> {
> }
>
> Since srcDocBytes and fSrcBytes are pointers this initialization creates
> copy of the pointer (srcDocBytes) and not copy of the content it points to. If this was nor true BTW then it would be wrong again because copy would be created unconditionally regardlis of the value of fAdopted.
>
> Another way to easily verify how wrong things are here
> is to search in MemBufInputSource.cpp for fAdopted. Then you will see that it only appears in initialization and in the destruction conditional I quoted. This can not be true because creation of a copy of the arg string is supposed to depend on it.
No, the creation of a copy is not dependent on the flag - just whether the class should delete it. Having a parameter like this can tidy up calling code and offer possible optimizations (you only have to create 1 copy of the string). You will find this used in a fair few places in xerces.
>
> BTW - I found out this issue out not by mere code
> inspection but the hard way after debugging some
> "magic" segfaults...
I hate those :) I never say never, but I don't think this is the issue. The only way I can see this happening is if you call
1) Make a MemBufInputSource with adopt set to true
2) call MemBufInputSource::setCopyBufToStream(false)
3) call makeStream()
4) delete the MemBufInputSource
5) do something with the BinMemInoutStream returned from makeStream
If you do that then it will break.
Regards,
Gareth
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Gareth Reakes (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_61102 ]
Gareth Reakes commented on XERCESC-1378:
----------------------------------------
Hi, the docs have been changed to reflect the actual behaviour. Thanks!
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
[jira] Commented: (XERCESC-1378) wrong string destruction in MemBufInputSource::~MemBufInputSource()
Posted by "Gareth Reakes (JIRA)" <xe...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XERCESC-1378?page=comments#action_61093 ]
Gareth Reakes commented on XERCESC-1378:
----------------------------------------
Hi, do you agree with my analysis?
> wrong string destruction in MemBufInputSource::~MemBufInputSource()
> -------------------------------------------------------------------
>
> Key: XERCESC-1378
> URL: http://issues.apache.org/jira/browse/XERCESC-1378
> Project: Xerces-C++
> Type: Bug
> Components: SAX/SAX2
> Versions: 2.6.0
> Environment: Any
> Reporter: Nikolay Ognyanov
>
> MemBufInputSource::~MemBufInputSource()
> {
> if (fAdopted)
> delete [] (XMLByte*)fSrcBytes;
> }
> This seems terribly wrong. Constructor initializes fSrcBytes
> with its argument srcDocBytes and this never changes, so the
> original argument string is deleted here and not a copy of it.
> Actual creation and destruction of a copy if fAdopted is set
> is handled in BinMemInputStream which is instantiated in MemBufInputSource::makeStream(). Therefore the code quoted
> above should be removed from the destructor and it should do
> nothing.
> Regards
> Nikolay
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org