[zeromq-dev] include/zmsg.hpp incorrect delete fix, valgrind fix, and rcvmore fix
Habbinga, Erik
Erik.Habbinga at schneider-electric.com
Thu May 9 18:37:40 CEST 2013
Hello,
We've found a few bugs in the latest version of include/zmsg.hpp from the guide, hopefully this is the right mailing list for a patch.
hunk 1-2: move ustring data instantiation closer to use, this silences a valgrind warning (unfortunately I don't have access to the warning anymore)
hunk 2: use int instead of int64_t for getsockopt(ZMQ_RCVMORE). int64_t with zeromq 3.2.2 on ARM is never returning more == 1, so multi part message framing fails. int64_t did work with zeromq 2.1.10 on ARM, oddly enough. Code in tests/test_reqrep_device.cpp is also using ints instead of int64_t for getsockopt(ZMQ_RCVMORE).
hunk 3: decode_uuid allocs memory with new [] and thus uuidbin needs to be freed with delete []
Thanks,
Erik
--- a/include/zmsg.hpp 2013-05-09 10:02:32.000000000 -0600
+++ b/include/zmsg.hpp 2013-05-09 10:04:59.000000000 -0600
@@ -99,7 +99,6 @@
std::cout << "E: " << error.what() << std::endl;
return false;
}
- ustring data = (unsigned char*) message.data();
//std::cerr << "recv: \"" << (unsigned char*) message.data() << "\", size " << message.size() << std::endl;
if (message.size() == 17 && ((unsigned char *)message.data())[0] == 0) {
char *uuidstr = encode_uuid((unsigned char*) message.data());
@@ -107,10 +106,10 @@
delete[] uuidstr;
}
else {
- data[message.size()] = 0;
+ ustring data((unsigned char*) message.data(), message.size());
push_back((char *)data.c_str());
}
- int64_t more = 0;
+ int more = 0;
size_t more_size = sizeof(more);
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
if (!more) {
@@ -128,7 +127,7 @@
unsigned char * uuidbin = decode_uuid ((char *) data.c_str());
message.rebuild(17);
memcpy(message.data(), uuidbin, 17);
- delete uuidbin;
+ delete[] uuidbin;
}
else {
message.rebuild(data.size());
More information about the zeromq-dev
mailing list