From 8487c78a0a648d766fcd730a0cc54ff7687e626f Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Tue, 14 Aug 2012 08:34:51 -0700 Subject: [PATCH] Adjust reference counts when splicing in short chain Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Chains.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index 8b13a0b5f..df77da2c3 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -3010,9 +3010,16 @@ sub optimize_level4( $$ ) { if ( $_->{simple} && ( $_->{target} || '' ) eq $name ) { trace( $sourceref, 'D', $rulenum + 1, $_ ) if $debug; splice @$rulesref, $rulenum, 1, @{$chainref->{rules}}; - if ( $debug ) { - while ( my $ruleref = shift @{$chainref->{rules}} ) { - trace ( $sourceref, 'I', $rulenum++, $ruleref ); + while ( my $ruleref = shift @{$chainref->{rules}} ) { + trace ( $sourceref, 'I', $rulenum++, $ruleref ) if $debug; + my $target = $ruleref->{target}; + + if ( $target && ( my $targetref = $tableref->{$target} ) ) { + # + # The rule target is a chain + # + add_reference( $chainref, $targetref ); + delete_reference( $sourceref, $targetref ); } } @@ -3021,7 +3028,6 @@ sub optimize_level4( $$ ) { last; } $rulenum++; - } } }