diff --git a/common.c b/common.c index cef60d0de..431d4e1af 100644 --- a/common.c +++ b/common.c @@ -1547,6 +1547,7 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out ) { wchar_t *cpy = wcsdup( val ); wchar_t *pos, *start; + wchar_t *next; if( !cpy ) { @@ -1557,12 +1558,19 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out ) { if( *pos == ARRAY_SEP ) { + *pos=0; - al_push( out, start==cpy?cpy:wcsdup(start) ); + next = start==cpy?cpy:wcsdup(start); + if( !next ) + DIE_MEM(); + al_push( out, next ); start=pos+1; } } - al_push( out, start==cpy?cpy:wcsdup(start) ); + next = start==cpy?cpy:wcsdup(start); + if( !next ) + DIE_MEM(); + al_push( out, next ); } } diff --git a/env.c b/env.c index 66bf1185c..a211d07ae 100644 --- a/env.c +++ b/env.c @@ -808,6 +808,9 @@ int env_set( const wchar_t *key, entry = malloc( sizeof( var_entry_t ) + sizeof(wchar_t )*(wcslen(val)+1)); + if( !entry ) + DIE_MEM(); + if( var_mode & ENV_EXPORT) { entry->export = 1; diff --git a/halloc.c b/halloc.c index f41377a15..0036922c5 100644 --- a/halloc.c +++ b/halloc.c @@ -179,12 +179,16 @@ void *halloc( void *context, size_t size ) alloc_spill += parent->scratch_free; #endif res = calloc( 1, size + HALLOC_BLOCK_SIZE ); + if( !res ) + DIE_MEM(); parent->scratch = (char *)res + size; parent->scratch_free = HALLOC_BLOCK_SIZE; } else { res = calloc( 1, size ); + if( !res ) + DIE_MEM(); } al_push( &parent->children, &late_free ); al_push( &parent->children, res ); @@ -198,7 +202,7 @@ void *halloc( void *context, size_t size ) me = (halloc_t *)calloc( 1, align_sz(sizeof(halloc_t)) + align_sz(size) + HALLOC_BLOCK_SIZE ); if( !me ) - return 0; + DIE_MEM(); #ifdef HALLOC_DEBUG parent_count++; #endif diff --git a/parser.c b/parser.c index d738eeb4b..7cf0bf1f2 100644 --- a/parser.c +++ b/parser.c @@ -2303,6 +2303,8 @@ static void eval_job( tokenizer *tok ) if( profile ) { p=malloc( sizeof(profile_element_t)); + if( !p ) + DIE_MEM(); p->cmd=0; al_push( &profile_data, p ); p->skipped=1;