From: Karen Etheridge Date: Wed, 13 Mar 2013 20:47:16 +0000 (-0700) Subject: RT#83929: fix memory leak in union types X-Git-Tag: 2.0800~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c05704596921f27fba4b1148dfed3ddd0d15795e;p=gitmo%2FMoose.git RT#83929: fix memory leak in union types --- diff --git a/Changes b/Changes index 8ec8923..64929a8 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ for, noteworthy changes. * Fix test failure in blead. RT #78085. + * Fix memory leak in type unions. (Karen Etheridge) RT#83929. + 2.0602 Mon, May 07, 2012 [BUG FIXES] diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index e2ed92d..0ee8165 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -29,7 +29,7 @@ sub new { %options, ); - $self->_set_constraint(sub { $self->check($_[0]) }); + $self->_set_constraint( $self->_compiled_type_constraint ); return $self; } diff --git a/xt/author/memory_leaks.t b/xt/author/memory_leaks.t index 0c0d04a..d4e0a75 100644 --- a/xt/author/memory_leaks.t +++ b/xt/author/memory_leaks.t @@ -7,6 +7,7 @@ use Test::Memory::Cycle; use Moose (); use Moose::Util qw( apply_all_roles ); +use Moose::Util::TypeConstraints; { package MyRole; @@ -99,4 +100,13 @@ no_leaks_ok( memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' ); } +{ + my $Str = find_type_constraint('Str'); + my $Undef = find_type_constraint('Undef'); + my $Str_or_Undef = Moose::Meta::TypeConstraint::Union->new( + type_constraints => [ $Str, $Undef ] ); + memory_cycle_ok($Str_or_Undef, 'union types do not leak'); +} + + done_testing;