safe calls to stdlib malloc/realloc/strdup

I added `memory.h` and `memory.c`

replaced all calls to malloc by SAFE_MALLOC,  realloc etc..

*SAFE_MALLOC* is a macro calling _safeMalloc(size_t n,__FILE__,__LINE__) it allocates the memory or exit(-1) on failure. The program exits after printing an error message.

*SAFE_REALLOC* calls _safeRealloc ... etc...