Check return values of malloc, realloc, strdup and strndup