]> git.proxmox.com Git - pve-guest-common.git/commitdiff
avoid cyclic reference in closure
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 19 Nov 2019 08:46:44 +0000 (09:46 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 19 Nov 2019 08:46:46 +0000 (09:46 +0100)
otherwise this leaks memory

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/GuestHelpers.pm

index 207fd9b0a166169d4da4624e61541408492f1ec1..34cdc857bb05df67e67a452e57739ad971a170d7 100644 (file)
@@ -7,6 +7,7 @@ use PVE::Tools;
 use PVE::Storage;
 
 use POSIX qw(strftime);
+use Scalar::Util qw(weaken);
 
 # We use a separate lock to block migration while a replication job
 # is running.
@@ -87,8 +88,8 @@ sub print_snapshot_tree {
     };
 
     # recursion function for displaying the tree
-    my $snapshottree;
-    $snapshottree = sub {
+    my $snapshottree_weak;
+    $snapshottree_weak = sub {
        my ($prefix, $root, $snapshots) = @_;
        my $e = $snapshots->{$root};
 
@@ -106,10 +107,12 @@ sub print_snapshot_tree {
        if ($e->{children}) {
            $prefix = "    $prefix";
            foreach my $child (sort $snaptimesort @{$e->{children}}) {
-               $snapshottree->($prefix, $child, $snapshots);
+               $snapshottree_weak->($prefix, $child, $snapshots);
            }
        }
     };
+    my $snapshottree = $snapshottree_weak;
+    weaken($snapshottree_weak);
 
     foreach my $root (sort $snaptimesort @roots) {
        $snapshottree->('`->', $root, $snapshots);