only change buflen if realloc succeeds