Guard realloc usage for failure

We attempt to realloc return value buffers so that we only use the needed amount
(nominally less than the maximum). When realloc fails, it returns a NULL but
does not modify the original buffer. We were always using the realloc return
which could result in assigning NULL when, in fact, the data was valid.