From 7bfe57e2e031b87191c4b7db7dbaecde7c244ac1 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Tue, 25 Feb 2014 14:57:04 +0000 Subject: [PATCH 1/3] Fix bug where buffer was being deleted underneath async_write operation. Fix bug where member function called from async callback without holding valid shared_ptr to class. --- libethereum/PeerNetwork.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/libethereum/PeerNetwork.cpp b/libethereum/PeerNetwork.cpp index 828caec46..c77af38eb 100644 --- a/libethereum/PeerNetwork.cpp +++ b/libethereum/PeerNetwork.cpp @@ -483,19 +483,21 @@ bool PeerSession::checkPacket(bytesConstRef _msg) void PeerSession::sendDestroy(bytes& _msg) { clogS(NetLeft) << RLP(bytesConstRef(&_msg).cropped(8)); - std::shared_ptr buffer = std::make_shared(); - swap(*buffer, _msg); - if (!checkPacket(bytesConstRef(&*buffer))) + + if (!checkPacket(bytesConstRef(&_msg))) { cwarn << "INVALID PACKET CONSTRUCTED!"; - } - ba::async_write(m_socket, ba::buffer(*buffer), [=](boost::system::error_code ec, std::size_t length) + + auto self(shared_from_this()); + bytes* buffer = new bytes(std::move(_msg)); + ba::async_write(m_socket, ba::buffer(*buffer), [self,buffer](boost::system::error_code ec, std::size_t length) { + delete buffer; if (ec) { cwarn << "Error sending: " << ec.message(); - dropped(); + self->dropped(); } // cbug << length << " bytes written (EC: " << ec << ")"; }); @@ -504,17 +506,21 @@ void PeerSession::sendDestroy(bytes& _msg) void PeerSession::send(bytesConstRef _msg) { clogS(NetLeft) << RLP(_msg.cropped(8)); - std::shared_ptr buffer = std::make_shared(_msg.toBytes()); + if (!checkPacket(_msg)) { cwarn << "INVALID PACKET CONSTRUCTED!"; } - ba::async_write(m_socket, ba::buffer(*buffer), [=](boost::system::error_code ec, std::size_t length) + + auto self(shared_from_this()); + bytes* buffer = new bytes(_msg.toBytes()); + ba::async_write(m_socket, ba::buffer(*buffer), [self,buffer](boost::system::error_code ec, std::size_t length) { + delete buffer; if (ec) { cwarn << "Error sending: " << ec.message(); - dropped(); + self->dropped(); } // cbug << length << " bytes written (EC: " << ec << ")"; }); @@ -568,7 +574,7 @@ void PeerSession::start() void PeerSession::doRead() { auto self(shared_from_this()); - m_socket.async_read_some(boost::asio::buffer(m_data), [this, self](boost::system::error_code ec, std::size_t length) + m_socket.async_read_some(boost::asio::buffer(m_data), [this,self](boost::system::error_code ec, std::size_t length) { if (ec) { From 762b563b4f7ce93f1382ba395984c0182aa087c5 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Tue, 25 Feb 2014 16:05:07 +0000 Subject: [PATCH 2/3] Be more helpful and create a branch when checking out cpp-ethereum. --- windows/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/bootstrap.sh b/windows/bootstrap.sh index 12935a91f..a3d643b53 100644 --- a/windows/bootstrap.sh +++ b/windows/bootstrap.sh @@ -12,7 +12,7 @@ if [[ ! $@ ]] || [ $1 == "fetch" ]; then if [ ! -d cpp-ethereum ]; then (set -x; git clone https://github.com/ethereum/cpp-ethereum.git) cd cpp-ethereum - (set -x; git checkout origin/develop) + (set -x; git checkout -b develop origin/develop) cd .. echo fi From 025a27ef3fdf3b698b1e2906346aa33dba42b370 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Tue, 25 Feb 2014 16:42:57 +0000 Subject: [PATCH 3/3] Check required binaries are present. --- windows/bootstrap.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/windows/bootstrap.sh b/windows/bootstrap.sh index a3d643b53..126889732 100644 --- a/windows/bootstrap.sh +++ b/windows/bootstrap.sh @@ -7,6 +7,19 @@ # - Visual Studio Express 2013 for Desktop # - On PATH: bash, git, git-svn, curl, sed, 7z +error_exit() { + echo $1 1>&2 + exit 1 +} + +for i in python perl curl git sed 7z; do + which $i &>/dev/null || error_exit "Could not find $i on PATH" +done + +if [ ! -d "$VS120COMNTOOLS" ]; then + error_exit "Couldn't find Visual Studio 2013" +fi + if [[ ! $@ ]] || [ $1 == "fetch" ]; then # fetch ethereum (develop branch) if [ ! -d cpp-ethereum ]; then