Skip to content

Commit 8fc6b6f

Browse files
author
Razvan Becheriu
committed
[#3190] fix ASAN warnings
1 parent 1b070fe commit 8fc6b6f

37 files changed

+925
-743
lines changed

src/lib/asiodns/tests/io_fetch_unittest.cc

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
8585

8686
bool tcp_short_send_; ///< If set to true, we do not send
8787
/// all data in the tcp response
88+
boost::shared_ptr<udp::socket> udp_socket_;
89+
boost::shared_ptr<tcp::socket> tcp_socket_;
90+
boost::shared_ptr<tcp::acceptor> tcp_acceptor_;
8891

8992
/// \brief Constructor
9093
IOFetchTest() :
@@ -139,7 +142,7 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
139142
// the class.)
140143
//
141144
// We could initialize the data with a single character, but as an added
142-
// check we'll make ssre that it has some structure.
145+
// check we'll make sure that it has some structure.
143146

144147
test_data_.clear();
145148
test_data_.reserve(MAX_SIZE);
@@ -149,6 +152,14 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
149152
}
150153
}
151154

155+
virtual ~IOFetchTest() {
156+
service_->restart();
157+
try {
158+
service_->poll();
159+
} catch (...) {
160+
}
161+
}
162+
152163
/// \brief UDP Response handler (the "remote UDP DNS server")
153164
///
154165
/// When IOFetch is sending data, this response handler emulates the remote
@@ -343,7 +354,7 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
343354

344355
} else {
345356

346-
// For all subsequent times, send the remainder, maximised to
357+
// For all subsequent times, send the remainder, maximized to
347358
// whatever we have chosen for the maximum send size.
348359
amount = min(tcp_send_size_,
349360
(send_buffer_.size() - send_cumulative_));
@@ -542,25 +553,27 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
542553
}
543554

544555
// Socket into which the connection will be accepted.
545-
tcp::socket socket(service_->getInternalIOService());
556+
tcp_socket_.reset(new tcp::socket(service_->getInternalIOService()));
546557

547558
// Acceptor object - called when the connection is made, the handler
548559
// will initiate a read on the socket.
549-
tcp::acceptor acceptor(service_->getInternalIOService(),
550-
tcp::endpoint(tcp::v4(), TEST_PORT));
551-
acceptor.async_accept(socket,
552-
std::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, ph::_1));
560+
tcp_acceptor_.reset(new tcp::acceptor(service_->getInternalIOService(),
561+
tcp::endpoint(tcp::v4(), TEST_PORT)));
562+
tcp_acceptor_->async_accept(*tcp_socket_,
563+
std::bind(&IOFetchTest::tcpAcceptHandler,
564+
this, tcp_socket_.get(), ph::_1));
553565

554566
// Post the TCP fetch object to send the query and receive the response.
555567
service_->post(tcp_fetch_);
556568

557569
// ... and execute all the callbacks. This exits when the fetch
558570
// completes.
559571
service_->run();
560-
EXPECT_TRUE(run_); // Make sure the callback did execute
561572

562573
// Tidy up
563-
socket.close();
574+
tcp_socket_->close();
575+
576+
EXPECT_TRUE(run_); // Make sure the callback did execute
564577
}
565578

566579
/// Perform a send/receive test over UDP
@@ -574,28 +587,29 @@ class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Call
574587
protocol_ = IOFetch::UDP;
575588

576589
// Set up the server.
577-
udp::socket socket(service_->getInternalIOService(), udp::v4());
578-
socket.set_option(socket_base::reuse_address(true));
579-
socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
590+
udp_socket_.reset(new udp::socket(service_->getInternalIOService(), udp::v4()));
591+
udp_socket_->set_option(socket_base::reuse_address(true));
592+
udp_socket_->bind(udp::endpoint(TEST_HOST, TEST_PORT));
580593
return_data_ = "Message returned to the client";
581594

582595
udp::endpoint remote;
583-
socket.async_receive_from(boost::asio::buffer(receive_buffer_,
584-
sizeof(receive_buffer_)),
585-
remote,
586-
std::bind(&IOFetchTest::udpReceiveHandler,
587-
this, &remote, &socket,
588-
ph::_1, ph::_2, bad_qid, second_send));
596+
udp_socket_->async_receive_from(boost::asio::buffer(receive_buffer_,
597+
sizeof(receive_buffer_)),
598+
remote,
599+
std::bind(&IOFetchTest::udpReceiveHandler,
600+
this, &remote, udp_socket_.get(),
601+
ph::_1, ph::_2, bad_qid, second_send));
589602
service_->post(udp_fetch_);
590603
if (debug_) {
591604
cout << "udpSendReceive: async_receive_from posted,"
592605
"waiting for callback" << endl;
593606
}
594607
service_->run();
595608

596-
socket.close();
609+
// Tidy up
610+
udp_socket_->close();
597611

598-
EXPECT_TRUE(run_);
612+
EXPECT_TRUE(run_); // Make sure the callback did execute
599613
}
600614
};
601615

src/lib/asiolink/botan_boost_tls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
108108
template <typename Callback, typename TlsStreamImpl>
109109
TlsStreamBase<Callback, TlsStreamImpl>::
110110
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
111-
: StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
111+
: StreamService(io_service, context),
112+
TlsStreamImpl(io_service->getInternalIOService(),
112113
context->getContext()), role_(context->getRole()) {
113114
}
114115

src/lib/asiolink/botan_tls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ typedef boost::asio::ip::tcp::socket TlsStreamImpl;
9696
template <typename Callback, typename TlsStreamImpl>
9797
TlsStreamBase<Callback, TlsStreamImpl>::
9898
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
99-
: StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService()),
99+
: StreamService(io_service, context),
100+
TlsStreamImpl(io_service->getInternalIOService()),
100101
role_(context->getRole()) {
101102
}
102103

src/lib/asiolink/common_tls.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ class TlsContextBase : private boost::noncopyable {
121121
class StreamService {
122122
public:
123123
/// @brief Constructor.
124-
StreamService(const IOServicePtr& io_service) : io_service_(io_service) {
124+
StreamService(const IOServicePtr& io_service, TlsContextPtr& tls_context) :
125+
io_service_(io_service), tls_context_(tls_context) {
125126
}
126127
private:
127128
/// @brief The IO service used to handle events.
128129
IOServicePtr io_service_;
130+
131+
/// @brief OpenSSL TLS context.
132+
TlsContextPtr tls_context_;
129133
};
130134

131135
/// @brief TLS stream base class.

src/lib/asiolink/interval_timer.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class IntervalTimerImpl :
5151
/// @param interval The interval used to start the timer.
5252
/// @param interval_mode The interval mode used by the timer.
5353
void setup(const IntervalTimer::Callback& cbfunc, const long interval,
54-
const IntervalTimer::Mode& interval_mode
55-
= IntervalTimer::REPEATING);
54+
const IntervalTimer::Mode& interval_mode = IntervalTimer::REPEATING);
5655

5756
/// @brief Callback function which calls the registerd callback.
5857
///

src/lib/asiolink/interval_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class IntervalTimer {
111111
/// \throw isc::BadValue interval is less than or equal to 0
112112
/// \throw isc::Unexpected internal runtime error
113113
void setup(const Callback& cbfunc, const long interval,
114-
const Mode& mode = REPEATING);
114+
const Mode& mode = REPEATING);
115115

116116
/// Cancel the timer.
117117
///

src/lib/asiolink/io_service.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class IOServiceImpl {
2929
};
3030

3131
/// \brief The destructor.
32-
~IOServiceImpl() {};
32+
~IOServiceImpl() {
33+
};
3334
//@}
3435

3536
/// \brief Start the underlying event loop.

src/lib/asiolink/openssl_tls.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
118118
template <typename Callback, typename TlsStreamImpl>
119119
TlsStreamBase<Callback, TlsStreamImpl>::
120120
TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
121-
: StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
121+
: StreamService(io_service, context),
122+
TlsStreamImpl(io_service->getInternalIOService(),
122123
context->getContext()), role_(context->getRole()) {
123124
}
124125

@@ -142,7 +143,8 @@ class TlsStream : public TlsStreamBase<Callback, TlsStreamImpl> {
142143
}
143144

144145
/// @brief Destructor.
145-
virtual ~TlsStream() { }
146+
virtual ~TlsStream() {
147+
}
146148

147149
/// @brief TLS Handshake.
148150
///

src/lib/asiolink/tests/interval_timer_unittest.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,34 @@ using namespace isc::asiolink;
2525
class IntervalTimerTest : public ::testing::Test {
2626
protected:
2727
IntervalTimerTest() :
28-
io_service_(new IOService()), timer_called_(false), timer_cancel_success_(false)
29-
{}
30-
~IntervalTimerTest() {}
28+
io_service_(new IOService()), timer_called_(false),
29+
timer_cancel_success_(false) {
30+
}
31+
~IntervalTimerTest() {
32+
io_service_->restart();
33+
try {
34+
io_service_->poll();
35+
} catch (...) {
36+
}
37+
}
3138
class TimerCallBack {
3239
public:
3340
TimerCallBack(IntervalTimerTest* test_obj) : test_obj_(test_obj) {}
3441
void operator()() const {
3542
test_obj_->timer_called_ = true;
3643
test_obj_->io_service_->stop();
37-
return;
3844
}
3945
private:
4046
IntervalTimerTest* test_obj_;
4147
};
4248
class TimerCallBackCounter {
4349
public:
4450
TimerCallBackCounter(IntervalTimerTest* test_obj) :
45-
test_obj_(test_obj)
46-
{
51+
test_obj_(test_obj) {
4752
counter_ = 0;
4853
}
4954
void operator()() {
5055
++counter_;
51-
return;
5256
}
5357
int counter_;
5458
private:
@@ -60,8 +64,8 @@ class IntervalTimerTest : public ::testing::Test {
6064
IntervalTimer* timer,
6165
TimerCallBackCounter& counter)
6266
: test_obj_(test_obj), timer_(timer), counter_(counter), count_(0),
63-
prev_counter_(-1)
64-
{}
67+
prev_counter_(-1) {
68+
}
6569
void operator()() {
6670
++count_;
6771
if (count_ == 1) {
@@ -80,7 +84,6 @@ class IntervalTimerTest : public ::testing::Test {
8084
test_obj_->timer_cancel_success_ = true;
8185
}
8286
}
83-
return;
8487
}
8588
private:
8689
IntervalTimerTest* test_obj_;
@@ -92,8 +95,8 @@ class IntervalTimerTest : public ::testing::Test {
9295
class TimerCallBackCanceller {
9396
public:
9497
TimerCallBackCanceller(unsigned int& counter, IntervalTimer& itimer) :
95-
counter_(counter), itimer_(itimer)
96-
{}
98+
counter_(counter), itimer_(itimer) {
99+
}
97100
void operator()() {
98101
++counter_;
99102
itimer_.cancel();
@@ -106,8 +109,8 @@ class IntervalTimerTest : public ::testing::Test {
106109
public:
107110
TimerCallBackOverwriter(IntervalTimerTest* test_obj,
108111
IntervalTimer& timer)
109-
: test_obj_(test_obj), timer_(timer), count_(0)
110-
{}
112+
: test_obj_(test_obj), timer_(timer), count_(0) {
113+
}
111114
void operator()() {
112115
++count_;
113116
if (count_ == 1) {
@@ -121,7 +124,6 @@ class IntervalTimerTest : public ::testing::Test {
121124
// We should stop here.
122125
test_obj_->io_service_->stop();
123126
}
124-
return;
125127
}
126128
private:
127129
IntervalTimerTest* test_obj_;
@@ -135,7 +137,6 @@ class IntervalTimerTest : public ::testing::Test {
135137
}
136138
void operator()() {
137139
++counter_;
138-
return;
139140
}
140141
private:
141142
IntervalTimerTest* test_obj_;

src/lib/asiolink/tests/tcp_acceptor_unittest.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class TCPClient : public boost::noncopyable {
6464
/// connect() to connect to the server.
6565
///
6666
/// @param io_service IO service to be stopped on error.
67-
explicit TCPClient(const IOServicePtr& io_service)
68-
: io_service_(io_service), socket_(io_service_->getInternalIOService()) {
67+
explicit TCPClient(const IOServicePtr& io_service, bool& running)
68+
: io_service_(io_service), socket_(io_service_->getInternalIOService()),
69+
running_(running) {
6970
}
7071

7172
/// @brief Destructor.
@@ -94,6 +95,9 @@ class TCPClient : public boost::noncopyable {
9495
///
9596
/// @param ec Error code.
9697
void connectHandler(const boost::system::error_code& ec) {
98+
if (!running_) {
99+
return;
100+
}
97101
if (ec) {
98102
// One would expect that async_connect wouldn't return EINPROGRESS
99103
// error code, but simply wait for the connection to get
@@ -123,6 +127,8 @@ class TCPClient : public boost::noncopyable {
123127
/// @brief A socket used for the connection.
124128
boost::asio::ip::tcp::socket socket_;
125129

130+
/// @brief Flag which indicates if the test is still running.
131+
bool& running_;
126132
};
127133

128134
/// @brief Pointer to the TCPClient.
@@ -206,13 +212,20 @@ class TCPAcceptorTest : public ::testing::Test {
206212
SERVER_PORT),
207213
endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
208214
clients_(), connections_num_(0), aborted_connections_num_(0),
209-
max_connections_(1) {
215+
max_connections_(1), running_(true) {
210216
test_timer_.setup(std::bind(&TCPAcceptorTest::timeoutHandler, this),
211217
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
212218
}
213219

214220
/// @brief Destructor.
215221
virtual ~TCPAcceptorTest() {
222+
running_ = false;
223+
test_timer_.cancel();
224+
io_service_->restart();
225+
try {
226+
io_service_->poll();
227+
} catch (...) {
228+
}
216229
}
217230

218231
/// @brief Specifies how many new connections are expected before the IO
@@ -264,7 +277,7 @@ class TCPAcceptorTest : public ::testing::Test {
264277
/// This method creates TCPClient instance and retains it in the clients_
265278
/// list.
266279
void connect() {
267-
TCPClientPtr client(new TCPClient(io_service_));
280+
TCPClientPtr client(new TCPClient(io_service_, running_));
268281
clients_.push_back(client);
269282
clients_.back()->connect();
270283
}
@@ -333,6 +346,9 @@ class TCPAcceptorTest : public ::testing::Test {
333346

334347
/// @brief Connections limit.
335348
unsigned int max_connections_;
349+
350+
/// @brief Flag which indicates if the test is still running.
351+
bool running_;
336352
};
337353

338354
// Test TCPAcceptor::asyncAccept.

0 commit comments

Comments
 (0)