Initialize XmppConnection::is_client_ properly in the constructor

Bug #1594533 reported by Ananth Suryanarayana
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Juniper Openstack
Status tracked in Trunk
Trunk
Fix Committed
Medium
Ananth Suryanarayana

Bug Description

XmppConnection::XmppConenction() uses uninitialized is_client_ (or uses it too soon) in the constructor in GetTaskInstance()

This diff reflects the problem and the fix.

diff --git a/src/xmpp/xmpp_connection.cc b/src/xmpp/xmpp_connection.cc
index c69b0d2..86e4253 100644
--- a/src/xmpp/xmpp_connection.cc
+++ b/src/xmpp/xmpp_connection.cc
@@ -47,7 +47,7 @@ XmppConnection::XmppConnection(TcpServer *server,
                   *server->event_manager()->io_service(),
                   "Xmpp keepalive timer",
                   TaskScheduler::GetInstance()->GetTaskId("xmpp::StateMachine"),
- GetTaskInstance())),
+ GetTaskInstance(config->ClientOnly()))),
       is_client_(config->ClientOnly()),
       log_uve_(config->logUVE),
       admin_down_(false),
@@ -131,10 +131,10 @@ XmppSession *XmppConnection::CreateSession() {
 // same value as before.
 // Do not make this method virtual since it gets called from the constructor.
 //
-int XmppConnection::GetTaskInstance() const {
- if (is_client_)
- return 0;

+int XmppConnection::GetTaskInstance(bool is_client) const {
+ if (is_client)
+ return 0;
     IpAddress address = endpoint().address();
     int thread_count = TaskScheduler::GetInstance()->HardwareThreadCount();
     if (address.is_v4()) {
diff --git a/src/xmpp/xmpp_connection.h b/src/xmpp/xmpp_connection.h
index 39c07e0..d88b383 100644
--- a/src/xmpp/xmpp_connection.h
+++ b/src/xmpp/xmpp_connection.h
@@ -72,7 +72,7 @@ public:
     std::string local_endpoint_string() const;
     TcpServer *server() { return server_; }
     XmppSession *CreateSession();
- int GetTaskInstance() const;
+ int GetTaskInstance() const { return GetTaskInstance(is_client_); }

     std::string ToString() const;
     std::string ToUVEKey() const;
@@ -242,6 +242,7 @@ private:
                                     std::string error_message);
     XmppStanza::XmppMessage *XmppDecode(const std::string &msg);
     void LogKeepAliveSend();
+ int GetTaskInstance(bool is_client) const;

     boost::asio::ip::tcp::endpoint endpoint_;
     boost::asio::ip::tcp::endpoint local_endpoint_;

Revision history for this message
OpenContrail Admin (ci-admin-f) wrote : [Review update] master

Review in progress for https://review.opencontrail.org/21307
Submitter: Ananth Suryanarayana (<email address hidden>)

Nischal Sheth (nsheth)
tags: added: contrail-control xmpp
Revision history for this message
OpenContrail Admin (ci-admin-f) wrote : A change has been merged

Reviewed: https://review.opencontrail.org/21307
Committed: http://github.org/Juniper/contrail-controller/commit/287c24b50b605ca3d5deb7ee7b2c744d05a78a8d
Submitter: Zuul
Branch: master

commit 287c24b50b605ca3d5deb7ee7b2c744d05a78a8d
Author: Ananth Suryanarayana <email address hidden>
Date: Mon Jun 20 11:57:26 2016 -0700

Do not use not (yet) initialized is_client_ in XmppConnection contructor

Change-Id: I0d2a4d9a7149f0cc047a3b7e9ec70051d4635160
Closes-Bug: #1594533

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.