wmail: use realloc(3) and handle allocation failures.

This commit is contained in:
Jeremy Sowden 2019-06-12 21:37:23 +01:00 committed by Carlos R. Mafra
parent 0fb61f1e49
commit 0360aff8e8
2 changed files with 12 additions and 10 deletions

View file

@ -139,9 +139,9 @@ static bool Tokenize( const char *line, const char **id, const char **value )
return false;
}
static void AddSenderToSkipList( char *sender )
static void AddSenderToSkipList( char *sender )
{
int numNames, i;
size_t numNames;
char **skipName, **newList;
for( skipName = config.skipNames, numNames = 0;
@ -154,15 +154,17 @@ static void AddSenderToSkipList( char *sender )
}
TRACE( "adding \"%s\" to skip-list of currently %d names\n", sender, numNames );
newList = malloc( sizeof(char *) * (numNames + 2) );
newList = realloc( config.skipNames, sizeof *config.skipNames * (numNames + 2) );
for( i = 0; i < numNames; ++i )
newList[i] = config.skipNames[i];
if( newList == NULL )
{
WARNING( "Cannot allocate memory for skip list.\n");
return;
}
newList[i] = sender;
newList[i+1] = NULL;
free( config.skipNames );
config.skipNames = newList;
config.skipNames[numNames++] = sender;
config.skipNames[numNames++] = NULL;
}
void ResetConfigStrings( void )

View file

@ -1252,8 +1252,8 @@ static bool SkipSender( char *address )
size_t len = strlen( address );
// remove trailing '\n' got from fgets
if( address[len-1] == '\n' )
address[len-1] = '\0';
if( address[len - 1] == '\n' )
address[len - 1] = '\0';
for( skipName = config.skipNames;
skipName != NULL && *skipName != NULL; skipName++ )