[pve-devel] memory leak in PVE/QMPClient.pm

Stefan Priebe - Profihost AG s.priebe at profihost.ag
Fri Oct 26 11:36:32 CEST 2012


Hello list,

while debugging i found a memory leak in PVE/QMPClient.pm. The leak 
happens due to the self reference of $mux and setting $self as callback 
of mux.

Code:
sub new {
     my ($class, $eventcb) = @_;

     my $mux = new IO::Multiplex;

     my $self = bless {
         mux => $mux,
         fhs => {}, # $vmid => fh
         fhs_lookup => {}, # $fh => $vmid
         queue => {},
         current => {},
         errors => {},
     }, $class;

     $self->{eventcb} = $eventcb if $eventcb;

     $mux->set_callback_object($self);

     return $self;
}

To fix this we need a DESTROY function in QMPClient:
sub DESTROY {
     my ($self) = @_;

     $self->{mux} = undef;
}

This is enough to remove the circular reference.

Stefan



More information about the pve-devel mailing list