mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-02 19:35:29 +08:00
problem: memory issues, access uninitiailized memory and leak
This commit is contained in:
parent
c4d0146f2c
commit
bbfed6b8d0
@ -941,6 +941,7 @@ int zmq::socket_base_t::connect (const char *addr_)
|
||||
if (protocol == "udp") {
|
||||
if (options.type != ZMQ_RADIO) {
|
||||
errno = ENOCOMPATPROTO;
|
||||
LIBZMQ_DELETE(paddr);
|
||||
EXIT_MUTEX ();
|
||||
return -1;
|
||||
}
|
||||
|
@ -180,16 +180,31 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in* addr)
|
||||
strcat (address, port);
|
||||
}
|
||||
|
||||
int zmq::udp_engine_t::resolve_raw_address (char *name_, int length_)
|
||||
int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_)
|
||||
{
|
||||
const char *delimiter = strrchr (name_, ':');
|
||||
memset (&raw_address, 0, sizeof raw_address);
|
||||
|
||||
const char *delimiter = NULL;
|
||||
|
||||
// Find delimiter, cannot use memrchr as it is not supported on windows
|
||||
if (length_ != 0) {
|
||||
int chars_left = length_;
|
||||
char *current_char = name_ + length_;
|
||||
do {
|
||||
if (*(--current_char) == ':') {
|
||||
delimiter = current_char;
|
||||
break;
|
||||
}
|
||||
} while (--chars_left != 0);
|
||||
}
|
||||
|
||||
if (!delimiter) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string addr_str (name_, delimiter - name_);
|
||||
std::string port_str (delimiter + 1);
|
||||
std::string port_str (delimiter + 1, name_ + length_ - delimiter - 1);
|
||||
|
||||
// Parse the port number (0 is not a valid port).
|
||||
uint16_t port = (uint16_t) atoi (port_str.c_str ());
|
||||
|
@ -46,7 +46,7 @@ namespace zmq
|
||||
|
||||
private:
|
||||
|
||||
int resolve_raw_address (char *addr_, int length_);
|
||||
int resolve_raw_address (char *addr_, size_t length_);
|
||||
void sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in* addr);
|
||||
|
||||
bool plugged;
|
||||
|
Loading…
x
Reference in New Issue
Block a user