I am hoping this is the right place to get some help with this. I have written a sendmail milter for the purpose of allowing pop users to securely submit spam/ham to our spam filter for learning. Because the user's use pop accounts it's easiest for me to have them forward their incorrectly marked messages to a specific email address and only submit messages sent by an authenticated user to the spam learning system. I have written a Milter or Sendmail Filter to that end.
Everything seems to work as expected except over time it seems to eat up memory and I am not exactly sure why. I got some help from someone on the comp.mail.sendmail group which helped a little but it is still leaking memory somewhere.
This is my first project in C of any value. Previously I have only written small tutorial like programs from books or internet tutorials. I think I have a basic grasp of the concepts but I am still shaky in many areas.
The sendmail milter API calls a set of user supplied functions for each part of the smtp transaction, in order to keep track of message and connection specific data the API passes a pointer to a private data structure that is set up to hold all the information required for the milter. (If this is a review for one of you experts or described incorrectly please forgive me.).
I believe my problem has to be in the cleanup functions that receive the pointer to this data when a message ends and then clears out the message specific data and then when the smtp transaction ends and should then free all the memory used to store message/connection information again for use by the OS.
Here is a small snippet of the functions I am using. If you would like to see the full source code you can download a zipped tarball from http://www.fletchcom.com/spamhammilt-0.1.tar.gz
Code:void cleanup_envelope ( struct mlfi_priv *priv ) { if ( priv->envfrom ) { memset ( priv->envfrom,'\0',sizeof ( priv->envfrom ) ); } if ( priv->envrcpt ) { memset ( priv->envrcpt,'\0',sizeof ( priv->envrcpt ) ); } if ( priv->fd > -1 ) { close ( priv->fd ); priv->fd = '\0'; } if ( strlen ( priv->filename ) >0 ) { memset ( priv->filename,'\0',sizeof ( priv->filename ) ); } } void cleanup_connection ( struct mlfi_priv *priv ) { if ( priv->rhost ) { memset ( priv->rhost,'\0',sizeof ( priv->rhost ) ); } if ( priv->raddr ) { memset ( priv->raddr,'\0',sizeof ( priv->raddr ) ); } if ( priv->loglev > '\0' ) { priv->loglev = '\0'; } if ( priv->log_email > '\0' ) { priv->log_email = '\0'; } if ( priv->auth > '\0' ) { priv->auth = '\0'; } if ( priv->authid ) { memset ( priv->authid,'\0',sizeof ( &priv->authid ) ); } } int cleanup ( SMFICTX *ctx,int level ) { struct mlfi_priv *priv; priv = ( struct mlfi_priv * ) smfi_getpriv ( ctx ); if ( priv == NULL ) { return TRUE; } switch ( level ) { case ENVELOPE: ( void ) cleanup_envelope ( priv ); break; case CONNECTION: ( void ) cleanup_envelope ( priv ); ( void ) cleanup_connection ( priv ); free ( priv ); break; } smfi_setpriv ( ctx,NULL ); return TRUE; }



LinkBack URL
About LinkBacks



