From 65c25d18011c42a183788ec084c2d992e7d80159 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Wed, 17 Aug 2016 13:58:36 +0200 Subject: [PATCH 1/2] [4551] Fixed --- src/lib/dhcp/iface_mgr.cc | 8 ++++---- src/lib/dhcp/tests/iface_mgr_unittest.cc | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index 70561ba3bc..8afb0d60f1 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -887,7 +887,7 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { isc_throw(BadValue, "fractional timeout must be shorter than" " one million microseconds"); } - const SocketInfo* candidate = 0; + boost::shared_ptr candidate; IfacePtr iface; fd_set sockets; int maxfd = 0; @@ -972,7 +972,7 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { BOOST_FOREACH(iface, ifaces_) { BOOST_FOREACH(SocketInfo s, iface->getSockets()) { if (FD_ISSET(s.sockfd_, &sockets)) { - candidate = &(s); + candidate.reset(new SocketInfo(s)); break; } } @@ -997,7 +997,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ " one million microseconds"); } - const SocketInfo* candidate = 0; + boost::shared_ptr candidate; fd_set sockets; int maxfd = 0; @@ -1082,7 +1082,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ BOOST_FOREACH(IfacePtr iface, ifaces_) { BOOST_FOREACH(SocketInfo s, iface->getSockets()) { if (FD_ISSET(s.sockfd_, &sockets)) { - candidate = &(s); + candidate.reset(new SocketInfo(s)); break; } } diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc index efd21df6a5..5136a10ed3 100644 --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@ -2833,15 +2833,17 @@ TEST_F(IfaceMgrTest, unicastDuplicates) { NakedIfaceMgr ifacemgr; IfacePtr iface = ifacemgr.getIface(LOOPBACK); - if (iface) { + if (!iface) { cout << "Local loopback interface not found. Skipping test. " << endl; return; } // Tell the interface that it should bind to this global interface + // It is the first attempt so it should succeed EXPECT_NO_THROW(iface->addUnicast(IOAddress("2001:db8::1"))); // Tell the interface that it should bind to this global interface + // It is the second attempt so it should fail EXPECT_THROW(iface->addUnicast(IOAddress("2001:db8::1")), BadValue); } From 047a81ce35f334addea4f405babd2d400cd566d0 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 23 Aug 2016 12:27:45 +0200 Subject: [PATCH 2/2] [4551] Addressed comment (use scoped pointers) --- src/lib/dhcp/iface_mgr.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index 8afb0d60f1..2e34f30688 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -880,14 +880,13 @@ IfaceMgr::send(const Pkt4Ptr& pkt) { } -boost::shared_ptr -IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { +Pkt4Ptr IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { // Sanity check for microsecond timeout. if (timeout_usec >= 1000000) { isc_throw(BadValue, "fractional timeout must be shorter than" " one million microseconds"); } - boost::shared_ptr candidate; + boost::scoped_ptr candidate; IfacePtr iface; fd_set sockets; int maxfd = 0; @@ -997,7 +996,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ " one million microseconds"); } - boost::shared_ptr candidate; + boost::scoped_ptr candidate; fd_set sockets; int maxfd = 0;