Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azmq::message's move assignment operator leaks memory. #144

Open
JenSte opened this issue Aug 19, 2018 · 0 comments
Open

azmq::message's move assignment operator leaks memory. #144

JenSte opened this issue Aug 19, 2018 · 0 comments

Comments

@JenSte
Copy link

JenSte commented Aug 19, 2018

The move assignment operator of azmq::message is broken:

  • Replaces the held zmq_msg_t by the one from the assigned object (msg_ = rhs.msg_;) without freeing the original one.
  • Does not take self-assignment into account, the own msg_ is erroneously re-initialized by calling zmq_msg_init(&rhs.msg_);.

The following program demonstrates the problems:

#include <azmq/message.hpp>
#include <iostream>

int main()
{
    int major, minor, patch;
    zmq_version(&major, &minor, &patch);

    std::cout << "boost version: " << BOOST_LIB_VERSION << '\n'
              << "zmq version: " << major << '.' << minor << '.' << patch << '\n'
              << "azmq version: git-a8f54cc8\n"
              << "gcc version: " << __GNUC__ << '.' << __GNUC_MINOR__ << '.' << __GNUC_PATCHLEVEL__ << std::endl;

    azmq::message m1(50);
    azmq::message m2(60);

    // Internal message of 'm2' is not freed.
    m2 = std::move(m1);


    azmq::message m3(70);

    std::cout << "m3.data() = " << m3.data() << '\n'
              << "m3.size() = " << m3.size() << std::endl;

    // Self-assignment, original (70 bytes long) buffer lost.
    m3 = std::move(m3);

    std::cout << "m3.data() = " << m3.data() << '\n'
              << "m3.size() = " << m3.size() << std::endl;
}

Output:

boost version: 1_63
zmq version: 4.1.6
azmq version: git-a8f54cc8
gcc version: 7.3.1
m3.data() = 0x60b000000118
m3.size() = 70
m3.data() = 0x7ffcd071dad0
m3.size() = 0

=================================================================
==3499==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 210 byte(s) in 2 object(s) allocated from:
    #0 0x7f15e0a66850 in malloc (/lib64/libasan.so.4+0xde850)
    #1 0x7f15e022d1bf  (/lib64/libzmq.so.5+0x261bf)

SUMMARY: AddressSanitizer: 210 byte(s) leaked in 2 allocation(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant