Dino,
The memory that is supposed to be freed by these functions is being malloc()'ed by each user supplied callback function. I'll post one of the functions here to show you what they each do.
This is the first function called by sendmail for each message when a connection is made to the server.
Thanks for all the help. If it makes much difference the milters run multithreaded. The API takes care of all the multi threading which is why I only get a pointer to my private data for each function. I will also include the private data structure I have defined and hopefully that will give enough info to help you see where I might be going wrong.
Code:
sfsistat mlfi_connect ( SMFICTX *ctx,char *hname, _SOCK_ADDR *haddr )
{
/*
Set up and allocate space for a private structure to store all the email data in.
*/
smfi_setdbg ( 6 );
struct mlfi_priv *priv;
priv = ( struct mlfi_priv * ) smfi_getpriv ( ctx );
if ( priv == NULL )
{
priv = ( struct mlfi_priv * ) malloc ( sizeof ( struct mlfi_priv ) );
if ( priv == NULL )
{
syslog ( LOG_ERR,"mlfi_connect: Error getting private data storage for the connection" );
return SMFIS_TEMPFAIL;
}
}
/*
Set every byte of the structure to null, this cleans up the memory from previous data stored there and prevents
garbage data from entering the program
*/
memset ( priv,'\0',sizeof ( struct mlfi_priv ) );
/*
Register the pointer to the structure with sendmail so that it can pass it back to us in later callbacks
*/
if ( smfi_setpriv ( ctx,priv ) == MI_FAILURE )
{
free ( priv );
return SMFIS_TEMPFAIL;
}
/*
Store the remote ip if applicable and hostname. Default to "Local" if not available. E.g. Sendmail was called from the command line
*/
const void *mysaddr = NULL;
char host[INET6_ADDRSTRLEN];
switch ( haddr->sa_family )
{
default:
syslog ( LOG_ERR,"mlfi_connect: unsupported sa_family" );
break;
case AF_INET:
mysaddr = ( const void * ) & ( ( struct sockaddr_in * ) haddr )->sin_addr.s_addr;
break;
case AF_INET6:
mysaddr = ( const void * ) & ( ( struct sockaddr_in6 * ) haddr )->sin6_addr;
break;
}
if ( !inet_ntop ( haddr->sa_family,mysaddr,host,sizeof ( host ) ) )
{
syslog ( LOG_ERR,"mlfi_connect: inet_ntop failed" );
strcpy ( host,"*" );
}
strncpy ( priv->rhost,hname,strlen ( hname ) );
priv->rhost[strlen ( hname ) ]= '\0';
strncpy ( priv->raddr,host,sizeof ( host ) );
priv->rhost[sizeof ( host ) ] = '\0';
priv->log_email = FALSE;
return SMFIS_CONTINUE;
}
Private data structure
Code:
struct mlfi_priv
{
char envfrom[ADDRLEN+1];
char envrcpt[ADDRLEN+1];
char rhost[ADDRLEN+1];
char raddr[ADDRLEN+1];
char filename[ADDRLEN+1];
char authid[ADDRLEN+1];
int auth;
int fd;
int loglev;
int log_email;
};
ADDRLEN is 324