cleanup: Replace a few calls to malloc/realloc with safe_malloc