Without this, we might access memory that's already been freed, or
leak memory if in the C locale.
Peter Geoghegan
        }
 
        /* Just like strcoll(), strxfrm() expects a NUL-terminated string */
-       memcpy(tss->buf1, VARDATA_ANY(authoritative), len);
+       memcpy(tss->buf1, authoritative_data, len);
        tss->buf1[len] = '\0';
 
-       /* Don't leak memory here */
-       if (PointerGetDatum(authoritative) != original)
-           pfree(authoritative);
-
        for (;;)
        {
 #ifdef HAVE_LOCALE_T
 
    addHyperLogLog(&tss->abbr_card, hash);
 
+   /* Don't leak memory here */
+   if (PointerGetDatum(authoritative) != original)
+       pfree(authoritative);
+
    return res;
 }