I think I've found a memory leak in Set::Object::Weak. The attached test
case demonstrates the situation that fails, at least in my setup. The
output from that script on my computer is:
# linux x86_64-linux
# perl version 5.012004
# Moose-2.0202
# Set::Object-1.28
# Test::LeakTrace-0.13
ok 1 - Testing Set::Object for leaking (leaks 0 <= 0)
not ok 2 - Testing Set::Object::Weak for leaking (leaks 2 <= 0)
# Failed test 'Testing Set::Object::Weak for leaking (leaks 2 <= 0)'
# at Set_Object.t line 41.
# '2'
# <=
# '0'
# leaked SCALAR(0xeccce0) from Set_Object.t line 39.
# 38: $set->insert($obj);
# 39: $set->remove($obj);
# 40: }
# SV = IV(0xecccd8) at 0xeccce0
# REFCNT = 1
# FLAGS = (IOK,pIOK)
# IV = 0
# leaked ARRAY(0x1283740) from Set_Object.t line 38.
# 37: my $obj = Foo->new;
# 38: $set->insert($obj);
# 39: $set->remove($obj);
# SV = PVAV(0x14b2f30) at 0x1283740
# REFCNT = 2
# FLAGS = ()
# ARRAY = 0x14cbea0
# FILL = 0
# MAX = 3
# ARYLEN = 0x0
# FLAGS = (REAL)
# Elt No. 0
# SV = IV(0xecccd8) at 0xeccce0
# REFCNT = 1
# FLAGS = (IOK,pIOK)
# IV = 0
1..2
# Looks like you failed 1 test of 2.
Everything looks fine on the surface; $obj is free, when it leaves the
scope, and $set looks healthy when I inspect it e.g. with Data::Dump.
However, something still leaks, so my guess is that it's somewhere in
the XS.
Subject: | Set_Object.t |
use strict;
use warnings;
use Config;
use Test::More;
use Test::LeakTrace;
use Set::Object;
{
package Foo;
use Moose;
1;
}
{
no strict;
note join ' ', map {$Config{$_}} qw(osname archname);
note 'perl version ', $];
note $_,'-',${"${_}::VERSION"} for qw{Moose Set::Object Test::LeakTrace};
}
my $set;
{
$set = Set::Object->new;
no_leaks_ok {
{
my $obj = Foo->new;
$set->insert($obj);
$set->remove($obj);
}
} 'Testing Set::Object for leaking';
}
{
$set = Set::Object::Weak->new;
no_leaks_ok {
{
my $obj = Foo->new;
$set->insert($obj);
$set->remove($obj);
}
} 'Testing Set::Object::Weak for leaking';
}
done_testing;