Subject: | Autovivification causes memory leak in Net::DBus::Reactor |
Net::DBus::Reactor will autovivify undefined elements in the timeouts array to empty hashes which won't be reused, leaking memory. Have only experienced this when calling a (remote) D-Bus method from inside another D-Bus method, but suspect this can be caused other ways too.
Subject: | net-dbus-timeout-autovivify.patch |
Author: Daniel Collins <daniel.collins@smoothwall.net>
Description: Don't leak memory by autovivifying undefined elements in the
reactor timeouts array to empty hashes. Seems to only happen when a D-Bus
method calls a D-Bus method in another service for some reason. Also prevent
the same from occuring if toggle_timeout() is called with an invalid key.
--- a/lib/Net/DBus/Reactor.pm
+++ b/lib/Net/DBus/Reactor.pm
@@ -417,7 +417,7 @@
my $timeout;
foreach (@{$self->{timeouts}}) {
- next unless $_->{enabled};
+ next unless defined && $_->{enabled};
my $expired = $now - $_->{last_fired};
my $interval = ($expired > $_->{interval} ? 0 : $_->{interval} - $expired);
@@ -453,7 +453,7 @@
my @callbacks;
foreach my $timeout (@{$self->{timeouts}}) {
- next unless $timeout->{enabled};
+ next unless defined($timeout) && $timeout->{enabled};
my $expired = $now - $timeout->{last_fired};
# Select typically returns a little (0-10 ms) before we
@@ -609,6 +609,9 @@
my $key = shift;
my $enabled = shift;
+ die "no timeout active with key '$key'"
+ unless defined $self->{timeouts}->[$key];
+
$self->{timeouts}->[$key]->{enabled} = $enabled;
$self->{timeouts}->[$key]->{interval} = shift if @_;
}