FYI,

*****My tests show that this is causing a memory leak.

Joe


------------------------------------------------------------------------------------------------------------
 my $spamtest = Mail::SpamAssassin->new();
 my $status = $spamtest->check($spamtest->parse($message));

 if ($status->is_spam()) {
   $message = $status->rewrite_mail();
 }
 else {
   ...
 }
 ...

 $status->finish();
------------------------------------------------------------------------------------------------------------

Joe Flowers wrote:
Hello everyone!  :)

Can I get away with this without any memory or resource leaks? Is this OK?

Thanks!

Joe

------------------------------------------------------------------------------------------------------------
  my $spamtest = Mail::SpamAssassin->new();
  my $status = $spamtest->check($spamtest->parse($message));

  if ($status->is_spam()) {
    $message = $status->rewrite_mail();
  }
  else {
    ...
  }
  ...

  $status->finish();
------------------------------------------------------------------------------------------------------------

**** PLEASE NOTICE the missing lines:

  my $mail = $spamtest->parse($message);
and
  $mail->finish();


------------------------------------------------------------------------------------------------------------

The docs at (http://spamassassin.apache.org/full/3.1.x/doc/Mail_SpamAssassin.html) say the following.

  my $spamtest = Mail::SpamAssassin->new();
  my $mail = $spamtest->parse($message);
  my $status = $spamtest->check($mail);

  if ($status->is_spam()) {
    $message = $status->rewrite_mail();
  }
  else {
    ...
  }
  ...

  $status->finish();
  $mail->finish();
------------------------------------------------------------------------------------------------------------

$status = $f->check ($mail)
........................

Note that the Mail::SpamAssassin object can be re-used for further messages without affecting this check; in OO terminology, the Mail::SpamAssassin object is a ``factory''. However, if you do this, be sure to call the finish() method on the status objects when you're done with them.

------------------------------------------------------------------------------------------------------------

//End.


Reply via email to