Fix memleak for long-lived resultsets. ghpr/closed/inspiring_6ae62c5c
Vladimir Timofeev [Wed, 10 Jul 2013 20:55:02 +0000 (00:55 +0400)]
It is a recursive attributes hash chain when call search on the same
resultset many times.

lib/DBIx/Class/Storage/DBI.pm
t/110leaktrace.t [new file with mode: 0644]

index 8ff9868..e5cf5ad 100644 (file)
@@ -2446,6 +2446,10 @@ sub _select_args {
   # invoked, and that's just bad...
 ###
 
+  # Small hack, remove potential infinity _sql_maker_select_args chain
+  # when call queries on the same resultset many times
+  delete $attrs->{_sqlmaker_select_args};
+
   return ( 'select', @{ $orig_attrs->{_sqlmaker_select_args} = [
     $ident, $select, $where, $attrs, @limit_args
   ]} );
diff --git a/t/110leaktrace.t b/t/110leaktrace.t
new file mode 100644 (file)
index 0000000..b50a784
--- /dev/null
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+BEGIN {
+    eval "use Test::LeakTrace";
+    plan 'skip_all' => 'Test::LeakTrace required for this tests' if $@;
+}
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 1;
+
+my $artist_rs = $schema->resultset('Artist')->search({},{order_by=>'me.artistid'});
+no_leaks_ok {
+    my @artists = $artist_rs->all;
+};