From 38097bef5dce8ad167335a97e911290339f1a0ad Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Fri, 11 Jan 2013 14:55:43 -0800 Subject: [PATCH] Correct an optimizer bug. - delete_chain_and_references() was only deleting the downward references and not the upward ones. Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Chains.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index f16b53fca..8f59e697e 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -1419,9 +1419,20 @@ sub delete_chain_and_references( $ ) { # We're going to delete this chain but first, we must delete all references to it. # my $tableref = $chain_table{$chainref->{table}}; - my $name1 = $chainref->{name}; - for ( @{$chainref->{rules}} ) { - decrement_reference_count( $tableref->{$_->{target}}, $name1 ) if $_->{target}; + my $name = $chainref->{name}; + + while ( my ( $chain, $references ) = each %{$chainref->{references}} ) { + # + # Delete all rules from $chain that have $name as their target + # + my $chain1ref = $tableref->{$chain}; + $chain1ref->{rules} = [ grep ( ( $_->{target} || '' ) ne $name, @{$chain1ref->{rules}} ) ]; + } + # + # Now decrement the reference count of all targets of this chain's rules + # + for ( grep $_, ( map( $_->{target}, @{$chainref->{rules}} ) ) ) { + decrement_reference_count( $tableref->{$_}, $name ); } delete_chain $chainref;