From b759725a611f6e3c62f7160abd153701d3842e66 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 26 Oct 2013 21:38:17 +0900 Subject: [PATCH] Peer: Use std::unique_ptr for res_ --- src/Peer.cc | 7 ++----- src/Peer.h | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Peer.cc b/src/Peer.cc index 06e08b8e..bf35e0bb 100644 --- a/src/Peer.cc +++ b/src/Peer.cc @@ -53,7 +53,6 @@ Peer::Peer(std::string ipaddr, uint16_t port, bool incoming): firstContactTime_(global::wallclock()), dropStartTime_(0), seeder_(false), - res_(nullptr), incoming_(incoming), localPeer_(false), disconnectedGracefully_(false) @@ -73,8 +72,7 @@ void Peer::usedBy(cuid_t cuid) void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength) { - delete res_; - res_ = new PeerSessionResource(pieceLength, totalLength); + res_ = make_unique(pieceLength, totalLength); res_->getNetStat().downloadStart(); updateSeeder(); } @@ -87,8 +85,7 @@ void Peer::reconfigureSessionResource(int32_t pieceLength, int64_t totalLength) void Peer::releaseSessionResource() { - delete res_; - res_ = nullptr; + res_.reset(); } void Peer::setPeerId(const unsigned char* peerId) diff --git a/src/Peer.h b/src/Peer.h index e146580c..3348bd49 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -74,7 +74,7 @@ private: bool seeder_; - PeerSessionResource* res_; + std::unique_ptr res_; // If true, port is assumed not to be a listening port. bool incoming_; @@ -129,7 +129,7 @@ public: // Returns true iff res_ != 0. bool isActive() const { - return res_ != nullptr; + return res_.get() != nullptr; } void setPeerId(const unsigned char* peerId);