mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Problem: raw malloc used unnecessarily
Solution: use std::string instead
This commit is contained in:
parent
30e2398e67
commit
4c3f115469
@ -117,17 +117,9 @@ zmq::session_base_t::session_base_t (class io_thread_t *io_thread_,
|
|||||||
_addr (addr_)
|
_addr (addr_)
|
||||||
#ifdef ZMQ_HAVE_WSS
|
#ifdef ZMQ_HAVE_WSS
|
||||||
,
|
,
|
||||||
_wss_hostname (NULL)
|
_wss_hostname (options_.wss_hostname)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef ZMQ_HAVE_WSS
|
|
||||||
if (options_.wss_hostname.length () > 0) {
|
|
||||||
_wss_hostname =
|
|
||||||
static_cast<char *> (malloc (options_.wss_hostname.length () + 1));
|
|
||||||
assert (_wss_hostname);
|
|
||||||
strcpy (_wss_hostname, options_.wss_hostname.c_str ());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const zmq::endpoint_uri_pair_t &zmq::session_base_t::get_endpoint () const
|
const zmq::endpoint_uri_pair_t &zmq::session_base_t::get_endpoint () const
|
||||||
@ -150,11 +142,6 @@ zmq::session_base_t::~session_base_t ()
|
|||||||
if (_engine)
|
if (_engine)
|
||||||
_engine->terminate ();
|
_engine->terminate ();
|
||||||
|
|
||||||
#ifdef ZMQ_HAVE_WSS
|
|
||||||
if (_wss_hostname)
|
|
||||||
free (_wss_hostname);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LIBZMQ_DELETE (_addr);
|
LIBZMQ_DELETE (_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,8 +695,8 @@ zmq::own_t *zmq::session_base_t::create_connecter_tcp (io_thread_t *io_thread_,
|
|||||||
zmq::own_t *zmq::session_base_t::create_connecter_ws (io_thread_t *io_thread_,
|
zmq::own_t *zmq::session_base_t::create_connecter_ws (io_thread_t *io_thread_,
|
||||||
bool wait_)
|
bool wait_)
|
||||||
{
|
{
|
||||||
return new (std::nothrow)
|
return new (std::nothrow) ws_connecter_t (io_thread_, this, options, _addr,
|
||||||
ws_connecter_t (io_thread_, this, options, _addr, wait_, false, NULL);
|
wait_, false, std::string ());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events
|
|||||||
#ifdef ZMQ_HAVE_WSS
|
#ifdef ZMQ_HAVE_WSS
|
||||||
// TLS handshake, we need to take a copy when the session is created,
|
// TLS handshake, we need to take a copy when the session is created,
|
||||||
// in order to maintain the value at the creation time
|
// in order to maintain the value at the creation time
|
||||||
char *_wss_hostname;
|
const std::string _wss_hostname;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZMQ_NON_COPYABLE_NOR_MOVABLE (session_base_t)
|
ZMQ_NON_COPYABLE_NOR_MOVABLE (session_base_t)
|
||||||
|
@ -74,7 +74,7 @@ zmq::ws_connecter_t::ws_connecter_t (class io_thread_t *io_thread_,
|
|||||||
address_t *addr_,
|
address_t *addr_,
|
||||||
bool delayed_start_,
|
bool delayed_start_,
|
||||||
bool wss_,
|
bool wss_,
|
||||||
const char *tls_hostname_) :
|
const std::string &tls_hostname_) :
|
||||||
stream_connecter_base_t (
|
stream_connecter_base_t (
|
||||||
io_thread_, session_, options_, addr_, delayed_start_),
|
io_thread_, session_, options_, addr_, delayed_start_),
|
||||||
_connect_timer_started (false),
|
_connect_timer_started (false),
|
||||||
|
@ -47,7 +47,7 @@ class ws_connecter_t : public stream_connecter_base_t
|
|||||||
address_t *addr_,
|
address_t *addr_,
|
||||||
bool delayed_start_,
|
bool delayed_start_,
|
||||||
bool wss_,
|
bool wss_,
|
||||||
const char *tls_hostname_);
|
const std::string &tls_hostname_);
|
||||||
~ws_connecter_t ();
|
~ws_connecter_t ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -89,7 +89,7 @@ class ws_connecter_t : public stream_connecter_base_t
|
|||||||
bool _connect_timer_started;
|
bool _connect_timer_started;
|
||||||
|
|
||||||
bool _wss;
|
bool _wss;
|
||||||
const char *_hostname;
|
const std::string &_hostname;
|
||||||
|
|
||||||
ZMQ_NON_COPYABLE_NOR_MOVABLE (ws_connecter_t)
|
ZMQ_NON_COPYABLE_NOR_MOVABLE (ws_connecter_t)
|
||||||
};
|
};
|
||||||
|
@ -294,8 +294,9 @@ void zmq::ws_listener_t::create_engine (fd_t fd_)
|
|||||||
i_engine *engine = NULL;
|
i_engine *engine = NULL;
|
||||||
if (_wss)
|
if (_wss)
|
||||||
#ifdef ZMQ_HAVE_WSS
|
#ifdef ZMQ_HAVE_WSS
|
||||||
engine = new (std::nothrow) wss_engine_t (
|
engine = new (std::nothrow)
|
||||||
fd_, options, endpoint_pair, _address, false, _tls_cred, NULL);
|
wss_engine_t (fd_, options, endpoint_pair, _address, false, _tls_cred,
|
||||||
|
std::string ());
|
||||||
#else
|
#else
|
||||||
assert (false);
|
assert (false);
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,7 +58,7 @@ zmq::wss_engine_t::wss_engine_t (fd_t fd_,
|
|||||||
ws_address_t &address_,
|
ws_address_t &address_,
|
||||||
bool client_,
|
bool client_,
|
||||||
void *tls_server_cred_,
|
void *tls_server_cred_,
|
||||||
const char *hostname_) :
|
const std::string &hostname_) :
|
||||||
ws_engine_t (fd_, options_, endpoint_uri_pair_, address_, client_),
|
ws_engine_t (fd_, options_, endpoint_uri_pair_, address_, client_),
|
||||||
_established (false),
|
_established (false),
|
||||||
_tls_client_cred (NULL)
|
_tls_client_cred (NULL)
|
||||||
@ -88,11 +88,13 @@ zmq::wss_engine_t::wss_engine_t (fd_t fd_,
|
|||||||
rc = gnutls_init (&_tls_session, GNUTLS_CLIENT | GNUTLS_NONBLOCK);
|
rc = gnutls_init (&_tls_session, GNUTLS_CLIENT | GNUTLS_NONBLOCK);
|
||||||
assert (rc == GNUTLS_E_SUCCESS);
|
assert (rc == GNUTLS_E_SUCCESS);
|
||||||
|
|
||||||
if (hostname_)
|
if (!hostname_.empty ())
|
||||||
gnutls_server_name_set (_tls_session, GNUTLS_NAME_DNS, hostname_,
|
gnutls_server_name_set (_tls_session, GNUTLS_NAME_DNS,
|
||||||
strlen (hostname_));
|
hostname_.c_str (), hostname_.size ());
|
||||||
|
|
||||||
gnutls_session_set_ptr (_tls_session, (void *) hostname_);
|
gnutls_session_set_ptr (
|
||||||
|
_tls_session,
|
||||||
|
hostname_.empty () ? NULL : const_cast<char *> (hostname_.c_str ()));
|
||||||
|
|
||||||
rc = gnutls_credentials_set (_tls_session, GNUTLS_CRD_CERTIFICATE,
|
rc = gnutls_credentials_set (_tls_session, GNUTLS_CRD_CERTIFICATE,
|
||||||
_tls_client_cred);
|
_tls_client_cred);
|
||||||
|
@ -46,7 +46,7 @@ class wss_engine_t : public ws_engine_t
|
|||||||
ws_address_t &address_,
|
ws_address_t &address_,
|
||||||
bool client_,
|
bool client_,
|
||||||
void *tls_server_cred_,
|
void *tls_server_cred_,
|
||||||
const char *hostname_);
|
const std::string &hostname_);
|
||||||
~wss_engine_t ();
|
~wss_engine_t ();
|
||||||
|
|
||||||
void out_event ();
|
void out_event ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user