per evitarti mal di testa certi futuri, controlla SEMPRE il valore restituito dalla realloc:

http://www.cplusplus.com/reference/c...tdlib/realloc/

Return Value
If the function failed to allocate the requested block of memory, a NULL pointer is returned, and the memory block pointed to by argument ptr is left unchanged.