wmail: handle allocation failures.
This commit is contained in:
parent
adf1164fba
commit
a8261ff053
|
@ -79,10 +79,13 @@ char *MakePathName( const char *dir, const char *file )
|
|||
else
|
||||
fullName = malloc( len1 + len2 + 1 );
|
||||
|
||||
if( fullName != NULL)
|
||||
{
|
||||
memcpy( fullName, dir, len1 );
|
||||
if( dir[len1-1] != '/' )
|
||||
fullName[len1++] = '/';
|
||||
memcpy( fullName + len1, file, len2 + 1 );
|
||||
}
|
||||
|
||||
return fullName;
|
||||
}
|
||||
|
|
|
@ -248,7 +248,9 @@ void ReadConfigFile( bool resetConfigStrings )
|
|||
|
||||
if(( usersHome = getenv( "HOME" )) != NULL )
|
||||
{
|
||||
char *fileName = MakePathName( usersHome, WMAIL_RC_FILE );
|
||||
char *fileName;
|
||||
if(( fileName = MakePathName( usersHome, WMAIL_RC_FILE )) != NULL )
|
||||
{
|
||||
FILE *f = fopen( fileName, "rt" );
|
||||
|
||||
if( f != NULL )
|
||||
|
@ -337,6 +339,9 @@ void ReadConfigFile( bool resetConfigStrings )
|
|||
} else {
|
||||
TRACE( "unable to open config-file \"%s\"\n", fileName );
|
||||
}
|
||||
} else {
|
||||
TRACE( "unable to allocate config-file\n" );
|
||||
}
|
||||
} else {
|
||||
TRACE( "no $HOME defined - config-file not read\n" );
|
||||
}
|
||||
|
|
|
@ -230,6 +230,12 @@ int main( int argc, char **argv )
|
|||
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
|
||||
}
|
||||
|
||||
if ( config.checksumFileName == NULL)
|
||||
{
|
||||
WARNING( "Cannot allocate checksum file-name.\n");
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
TRACE( "using checksum-file \"%s\"\n", config.checksumFileName );
|
||||
|
||||
// parse cmdline-args and overide defaults and cfg-file settings
|
||||
|
@ -630,6 +636,12 @@ void CheckMaildir()
|
|||
char *fullName = FileNameConcat( config.mailBox, dirEnt->d_name );
|
||||
struct stat fileStat;
|
||||
|
||||
if ( fullName == NULL )
|
||||
{
|
||||
WARNING( "Cannot allocate file/path\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
if( !stat( fullName, &fileStat ) == 0 ) {
|
||||
WARNING( "Can't stat file/path \"%s\"\n", fullName );
|
||||
free( fullName );
|
||||
|
@ -675,6 +687,12 @@ int TraverseDirectory( const char *name, bool isNewMail )
|
|||
unsigned long checksum = 0;
|
||||
name_t *name;
|
||||
|
||||
if ( fullName == NULL )
|
||||
{
|
||||
WARNING( "Cannot allocate file/path\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
if( !stat( fullName, &fileStat ) == 0 ) {
|
||||
WARNING( "Can't stat file/path \"%s\"\n", fullName );
|
||||
free( fullName );
|
||||
|
@ -823,7 +841,13 @@ void ParseMBoxFile( struct stat *fileStat )
|
|||
if( SkipSender( buf+6 ))
|
||||
goto NEXTMAIL;
|
||||
|
||||
InsertName( ParseFromField( buf+6 ), checksum, FLAG_INITIAL );
|
||||
char *name;
|
||||
if(( name = ParseFromField( buf+6 )) == NULL )
|
||||
{
|
||||
WARNING( "Could not parse From field\n" );
|
||||
break;
|
||||
}
|
||||
InsertName( name, checksum, FLAG_INITIAL );
|
||||
|
||||
++numMails;
|
||||
fromFound = 0;
|
||||
|
@ -868,8 +892,13 @@ void ParseMaildirFile( const char *fileName, unsigned long checksum,
|
|||
if( SkipSender( buf+6 ))
|
||||
break;
|
||||
|
||||
InsertName( ParseFromField( buf+6 ), checksum,
|
||||
isNewMail ? FLAG_INITIAL : FLAG_READ );
|
||||
char *name;
|
||||
if(( name = ParseFromField( buf+6 )) == NULL )
|
||||
{
|
||||
WARNING( "Could not parse From field\n" );
|
||||
break;
|
||||
}
|
||||
InsertName( name, checksum, isNewMail ? FLAG_INITIAL : FLAG_READ );
|
||||
|
||||
//++numMails;
|
||||
}
|
||||
|
@ -894,11 +923,12 @@ char *ParseFromField( char *buf )
|
|||
int maxLen = strlen( buf ) + 1;
|
||||
char *comment;
|
||||
|
||||
// FIXME: Uhm, those mallocs might fail...
|
||||
|
||||
fullName = malloc( maxLen );
|
||||
addressName = malloc( maxLen );
|
||||
comment = malloc( maxLen );
|
||||
if(( fullName = malloc( maxLen )) == NULL )
|
||||
return NULL;
|
||||
if(( addressName = malloc( maxLen )) == NULL )
|
||||
return NULL;
|
||||
if(( comment = malloc( maxLen )) == NULL )
|
||||
return NULL;
|
||||
|
||||
memset( fullName, '\0', maxLen );
|
||||
memset( addressName, '\0', maxLen );
|
||||
|
@ -1080,7 +1110,9 @@ void InsertName( char *name, unsigned long checksum, flag_t flag )
|
|||
name_t *item;
|
||||
|
||||
TRACE( "insertName: %X, \"%s\"\n", checksum, name );
|
||||
item = (name_t *)malloc( sizeof( name_t ));
|
||||
if (( item = malloc( sizeof( name_t ))) == NULL )
|
||||
return;
|
||||
|
||||
item->name = name; /*strdup( name );*/
|
||||
item->checksum = checksum;
|
||||
item->flag = flag;
|
||||
|
|
Loading…
Reference in a new issue