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

ZMQ::LibZMQ2 leaks memory in _zmq_recv #15

Closed
trinitum opened this issue Oct 8, 2012 · 2 comments
Closed

ZMQ::LibZMQ2 leaks memory in _zmq_recv #15

trinitum opened this issue Oct 8, 2012 · 2 comments

Comments

@trinitum
Copy link

trinitum commented Oct 8, 2012

If I run the following example I see that ZMQ Subscriber leaks memory:

use 5.010;
use strict;
use warnings;

use ZMQ;
use ZMQ::Constants qw(ZMQ_PUB ZMQ_SUB ZMQ_SUBSCRIBE);
use Time::HiRes qw(usleep);

if (fork) {
    $0 = "ZMQ Publisher";
    my $ctx = ZMQ::Context->new;
    my $sock = $ctx->socket(ZMQ_PUB);
    $sock->bind("tcp://*:7654");
    while (1) {
        $sock->send( "Foo" x 100, 0 );
        usleep(1000);
    }
}
else {
    sleep 1;
    $0 = "ZMQ Subscriber";
    my $ctx = ZMQ::Context->new;
    my $sock = $ctx->socket(ZMQ_SUB);
    $sock->connect("tcp://localhost:7654");
    $sock->setsockopt( ZMQ_SUBSCRIBE, '' );
    while (1) {
        my $msg = $sock->recv;
        $msg->close;
    }
}

I tested it on Debian Squeeze and Ubuntu 11.10 with libzmq 2.1.9 and 2.2.0.

The reason is seems that you're creating temporary zmq_msg_t structure and don't call zmq_msg_close on it. The following commit fixes the problem for me: trinitum/p5-ZMQ@6aa97bf

@lestrrat
Copy link
Collaborator

lestrrat commented Oct 9, 2012

You're absolutely right. That piece of code of mine looks like a cruft from some long ago.

@lestrrat
Copy link
Collaborator

lestrrat commented Oct 9, 2012

fixed, and released.

@lestrrat lestrrat closed this as completed Oct 9, 2012
int1ch pushed a commit to int1ch/p5-ZMQ that referenced this issue Aug 26, 2014
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

2 participants