Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b48ecf8

Browse files
committed
In bttext_abbrev_convert, move pfree to the right place.
Without this, we might access memory that's already been freed, or leak memory if in the C locale. Peter Geoghegan
1 parent 47fe4d2 commit b48ecf8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/backend/utils/adt/varlena.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2034,13 +2034,9 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
20342034
}
20352035

20362036
/* Just like strcoll(), strxfrm() expects a NUL-terminated string */
2037-
memcpy(tss->buf1, VARDATA_ANY(authoritative), len);
2037+
memcpy(tss->buf1, authoritative_data, len);
20382038
tss->buf1[len] = '\0';
20392039

2040-
/* Don't leak memory here */
2041-
if (PointerGetDatum(authoritative) != original)
2042-
pfree(authoritative);
2043-
20442040
for (;;)
20452041
{
20462042
#ifdef HAVE_LOCALE_T
@@ -2108,6 +2104,10 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
21082104

21092105
addHyperLogLog(&tss->abbr_card, hash);
21102106

2107+
/* Don't leak memory here */
2108+
if (PointerGetDatum(authoritative) != original)
2109+
pfree(authoritative);
2110+
21112111
return res;
21122112
}
21132113

0 commit comments

Comments
 (0)