2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-27 18:42:07 +00:00

Add a workaround for MSVC secure iterator problem where allowing the

destruction of an iterator to an already-destroyed string object results in
a program crash. Revert previous change to destroy buffers prior to
invoking the handler since it didn't fix the problem and wasn't cleaning
up all copies of the buffers anyway.


[SVN r41059]
This commit is contained in:
Christopher Kohlhoff
2007-11-13 12:50:27 +00:00
parent 970375748c
commit 45add4d11e
3 changed files with 20 additions and 25 deletions

View File

@@ -27,7 +27,7 @@
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_MSVC)
# if defined(_HAS_ITERATOR_DEBUGGING)
# if defined(_HAS_ITERATOR_DEBUGGING) && (_HAS_ITERATOR_DEBUGGING != 0)
# if !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
# define BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
# endif // !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
@@ -391,6 +391,11 @@ public:
{
}
~buffer_debug_check()
{
iter_ = Iterator();
}
void operator()()
{
*iter_;

View File

@@ -19,7 +19,6 @@
#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
#include <boost/optional.hpp>
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/buffer.hpp>
@@ -140,25 +139,23 @@ namespace detail
std::size_t bytes_transferred)
{
total_transferred_ += bytes_transferred;
buffers_->consume(bytes_transferred);
if ((*completion_condition_)(ec, total_transferred_)
|| buffers_->begin() == buffers_->end())
buffers_.consume(bytes_transferred);
if (completion_condition_(ec, total_transferred_)
|| buffers_.begin() == buffers_.end())
{
buffers_.reset();
completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
{
stream_.async_read_some(*buffers_, *this);
stream_.async_read_some(buffers_, *this);
}
}
//private:
AsyncReadStream& stream_;
boost::optional<buffers_type> buffers_;
buffers_type buffers_;
std::size_t total_transferred_;
boost::optional<CompletionCondition> completion_condition_;
CompletionCondition completion_condition_;
ReadHandler handler_;
};
@@ -239,9 +236,8 @@ namespace detail
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
if (streambuf_.size() == streambuf_.max_size()
|| (*completion_condition_)(ec, total_transferred_))
|| completion_condition_(ec, total_transferred_))
{
completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
@@ -256,7 +252,7 @@ namespace detail
AsyncReadStream& stream_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
std::size_t total_transferred_;
boost::optional<CompletionCondition> completion_condition_;
CompletionCondition completion_condition_;
ReadHandler handler_;
};

View File

@@ -17,10 +17,6 @@
#include <boost/asio/detail/push_options.hpp>
#include <boost/asio/detail/push_options.hpp>
#include <boost/optional.hpp>
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/bind_handler.hpp>
@@ -129,25 +125,23 @@ namespace detail
std::size_t bytes_transferred)
{
total_transferred_ += bytes_transferred;
buffers_->consume(bytes_transferred);
if ((*completion_condition_)(ec, total_transferred_)
|| buffers_->begin() == buffers_->end())
buffers_.consume(bytes_transferred);
if (completion_condition_(ec, total_transferred_)
|| buffers_.begin() == buffers_.end())
{
buffers_.reset();
completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
{
stream_.async_write_some(*buffers_, *this);
stream_.async_write_some(buffers_, *this);
}
}
//private:
AsyncWriteStream& stream_;
boost::optional<buffers_type> buffers_;
buffers_type buffers_;
std::size_t total_transferred_;
boost::optional<CompletionCondition> completion_condition_;
CompletionCondition completion_condition_;
WriteHandler handler_;
};