Handling realloc fails

Addressing issue : 'realloc may return NULL #23'