[Jifty-commit] r4711 - in jifty/trunk: lib/Jifty/Web

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Dec 16 16:27:20 EST 2007


Author: sartak
Date: Sun Dec 16 16:27:20 2007
New Revision: 4711

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Web/Menu.pm

Log:
 r49133 at onn:  sartak | 2007-12-16 16:27:08 -0500
 Fix a real memory leak in Jifty::Web::Menu due to copying a weak reference. Woo!


Modified: jifty/trunk/lib/Jifty/Web/Menu.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Menu.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Menu.pm	Sun Dec 16 16:27:20 2007
@@ -25,14 +25,15 @@
     my $package = shift;
     my $args = ref($_[0]) eq 'HASH' ? shift @_ : {@_};
 
-    
-
-    $args->{'_parent'} ||= delete $args->{'parent'};
-    weaken $args->{'_parent'} if $args->{'_parent'};
+    my $parent = delete $args->{'parent'};
 
     # Class::Accessor only wants a hashref;
-    $package->SUPER::new( $args);
+    my $self = $package->SUPER::new( $args);
+
+    # make sure our reference is weak
+    $self->parent($parent) if defined $parent;
 
+    return $self;
 }
 
 
@@ -45,20 +46,19 @@
 =head2 parent [MENU]
 
 Gets or sets the parent L<Jifty::Web::Menu> of this item; this defaults
-to null.
+to null. This ensures that the reference is weakened.
 
 =cut
 
 
 sub parent {
     my $self = shift;
-    my $parent;
     if (@_) {
-        $parent = shift;
-        weaken $parent;
+        $self->_parent(@_);
+        weaken $self->{_parent};
     }
 
-    return $self->_parent($parent);
+    return $self->_parent;
 }
 
 


More information about the Jifty-commit mailing list