Skip to content

Commit 77ae7f7

Browse files
committed
Plug memory leak in range_cmp function.
B-tree operators are not allowed to leak memory into the current memory context. Range_cmp leaked detoasted copies of the arguments. That caused a quick out-of-memory error when creating an index on a range column. Reported by Marian Krucina, bug #8468.
1 parent b2fc4d6 commit 77ae7f7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/backend/utils/adt/rangetypes.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,16 +1125,22 @@ range_cmp(PG_FUNCTION_ARGS)
11251125

11261126
/* For b-tree use, empty ranges sort before all else */
11271127
if (empty1 && empty2)
1128-
PG_RETURN_INT32(0);
1128+
cmp = 0;
11291129
else if (empty1)
1130-
PG_RETURN_INT32(-1);
1130+
cmp = -1;
11311131
else if (empty2)
1132-
PG_RETURN_INT32(1);
1132+
cmp = 1;
1133+
else
1134+
{
1135+
cmp = range_cmp_bounds(typcache, &lower1, &lower2);
1136+
if (cmp == 0)
1137+
cmp = range_cmp_bounds(typcache, &upper1, &upper2);
1138+
}
11331139

1134-
if ((cmp = range_cmp_bounds(typcache, &lower1, &lower2)) != 0)
1135-
PG_RETURN_INT32(cmp);
1140+
PG_FREE_IF_COPY(r1, 0);
1141+
PG_FREE_IF_COPY(r2, 1);
11361142

1137-
PG_RETURN_INT32(range_cmp_bounds(typcache, &upper1, &upper2));
1143+
PG_RETURN_INT32(cmp);
11381144
}
11391145

11401146
/* inequality operators using the range_cmp function */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy