Fix memory leak, circular reference on publish()

Reported, analised and fixed by Tiago Quintela and Nuno Mota.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
This commit is contained in:
Pedro Melo
2015-02-28 07:49:45 +00:00
parent 1c5a3526fd
commit f3fb375d10

View File

@@ -38,10 +38,14 @@ sub publish {
my $conn = $self->_random_connected_conn; my $conn = $self->_random_connected_conn;
croak "ERROR: there no active connections at this moment," unless $conn; croak "ERROR: there no active connections at this moment," unless $conn;
my @args;
if (ref($data[-1]) eq 'CODE' or !defined($data[-1])) { if (ref($data[-1]) eq 'CODE' or !defined($data[-1])) {
my $cb = pop @data; my $cb = pop @data;
push @data, sub { $cb->($self, $topic, \@data, @_) }
if $cb; if ($cb) {
my @cb_data = @data;
push @data, sub { $cb->($self, $topic, \@cb_data, @_) }
}
} }
return $conn->publish($topic, @data); return $conn->publish($topic, @data);