replace realloc with reallocarray where appropriate