Index: spamassassin.raw =================================================================== --- spamassassin.raw (revision 578776) +++ spamassassin.raw (working copy) @@ -349,6 +349,8 @@ ########################################################################### +setup_sig_handlers(); + # Everything below here needs ArchiveIterator ... my $iter = new Mail::SpamAssassin::ArchiveIterator( { @@ -409,10 +411,12 @@ ########################################################################### +my $mail; # global, so signal handler can clean it up; bug 5626 + # make sure it only returns false values so that result_sub() isn't called... sub wanted { my $dataref = $_[3]; - my $mail = $spamtest->parse($dataref); + $mail = $spamtest->parse($dataref); $count++; # This is a short cut -- doing white/black-list? Do it and return quickly. @@ -431,6 +435,7 @@ } $mail->finish(); + $mail = undef; return 1; } @@ -441,6 +446,7 @@ if ( !$opt{'test-mode'} ) { print $spamtest->remove_spamassassin_markup ($mail); $mail->finish(); + $mail = undef; return 1; } else { @@ -451,6 +457,7 @@ # my $new_mail = $spamtest->parse( $spamtest->remove_spamassassin_markup($mail) ); + $mail->finish(); $mail = $new_mail; } @@ -463,13 +470,14 @@ my $new_mail = $spamtest->parse( $spamtest->remove_spamassassin_markup($mail) ); $mail->finish(); + $mail = $new_mail; my $failed; - if ( $opt{'report'} && !$spamtest->report_as_spam($new_mail) ) { + if ( $opt{'report'} && !$spamtest->report_as_spam($mail) ) { $failed = 'report'; } - if ( $opt{'revoke'} && !$spamtest->revoke_as_spam($new_mail) ) { + if ( $opt{'revoke'} && !$spamtest->revoke_as_spam($mail) ) { $failed = 'revoke'; } @@ -478,7 +486,8 @@ warn "spamassassin: for more information, re-run with -D option to see debug output\n"; } - $new_mail->finish(); + $mail->finish(); + $mail = undef; return 1; } @@ -499,11 +508,32 @@ # clean up after ourselves $mail->finish(); + $mail = undef; + $status->finish(); return 1; } +########################################################################### + +sub setup_sig_handlers { + $SIG{HUP} = \&kill_handler; + $SIG{INT} = \&kill_handler; + $SIG{TERM} = \&kill_handler; + $SIG{PIPE} = \&kill_handler; +} + +sub kill_handler { + my ($sig) = @_; + warn "spamassassin: killed by SIG$sig\n"; + if ($mail) { + $mail->finish(); # bug 5626: remove temp files etc. + $mail = undef; + } + exit 0; +} + # --------------------------------------------------------------------------- =cut