aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-09-25 16:02:00 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-09-25 16:05:24 +0300
commit33936752829e3c6d4c463f3c974968b225304571 (patch)
tree271e9c9463660922ac05a4f13d6399c19ed4b7cb /src
parentea9a2bcea3a3372b7f296b1095aeebf65c27f32a (diff)
downloadpostgresql-33936752829e3c6d4c463f3c974968b225304571.tar.gz
postgresql-33936752829e3c6d4c463f3c974968b225304571.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/rangetypes.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c
index cd5c5f6621c..023df8c3e9e 100644
--- a/src/backend/utils/adt/rangetypes.c
+++ b/src/backend/utils/adt/rangetypes.c
@@ -1125,16 +1125,22 @@ range_cmp(PG_FUNCTION_ARGS)
/* For b-tree use, empty ranges sort before all else */
if (empty1 && empty2)
- PG_RETURN_INT32(0);
+ cmp = 0;
else if (empty1)
- PG_RETURN_INT32(-1);
+ cmp = -1;
else if (empty2)
- PG_RETURN_INT32(1);
+ cmp = 1;
+ else
+ {
+ cmp = range_cmp_bounds(typcache, &lower1, &lower2);
+ if (cmp == 0)
+ cmp = range_cmp_bounds(typcache, &upper1, &upper2);
+ }
- if ((cmp = range_cmp_bounds(typcache, &lower1, &lower2)) != 0)
- PG_RETURN_INT32(cmp);
+ PG_FREE_IF_COPY(r1, 0);
+ PG_FREE_IF_COPY(r2, 1);
- PG_RETURN_INT32(range_cmp_bounds(typcache, &upper1, &upper2));
+ PG_RETURN_INT32(cmp);
}
/* inequality operators using the range_cmp function */