]> granicus.if.org Git - postgresql/commitdiff
In bttext_abbrev_convert, move pfree to the right place.
authorRobert Haas <rhaas@postgresql.org>
Tue, 30 Jun 2015 03:53:05 +0000 (23:53 -0400)
committerRobert Haas <rhaas@postgresql.org>
Tue, 30 Jun 2015 03:53:05 +0000 (23:53 -0400)
Without this, we might access memory that's already been freed, or
leak memory if in the C locale.

Peter Geoghegan

src/backend/utils/adt/varlena.c

index 779729d724a8b45c851a8814189e10024fab94c3..2fbbf5475ece78fe38086faded6fed64781a4950 100644 (file)
@@ -2034,13 +2034,9 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
                }
 
                /* 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
@@ -2108,6 +2104,10 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
 
        addHyperLogLog(&tss->abbr_card, hash);
 
+       /* Don't leak memory here */
+       if (PointerGetDatum(authoritative) != original)
+               pfree(authoritative);
+
        return res;
 }