[postgis-tickets] r16360 - Avoid memory exhaustion when building a btree index (references #4004)
Paul Ramsey
pramsey at cleverelephant.ca
Fri Jan 26 04:43:51 PST 2018
Author: pramsey
Date: 2018-01-26 04:43:51 -0800 (Fri, 26 Jan 2018)
New Revision: 16360
Modified:
trunk/postgis/geography_btree.c
Log:
Avoid memory exhaustion when building a btree index (references #4004)
>From Edmund Horner
Modified: trunk/postgis/geography_btree.c
===================================================================
--- trunk/postgis/geography_btree.c 2018-01-24 01:51:53 UTC (rev 16359)
+++ trunk/postgis/geography_btree.c 2018-01-26 12:43:51 UTC (rev 16360)
@@ -51,6 +51,8 @@
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
int cmp = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
if (cmp < 0)
PG_RETURN_BOOL(true);
else
@@ -67,6 +69,8 @@
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
int cmp = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
if (cmp <= 0)
PG_RETURN_BOOL(true);
else
@@ -83,6 +87,8 @@
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
int cmp = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
if (cmp > 0)
PG_RETURN_BOOL(true);
else
@@ -99,6 +105,8 @@
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
int cmp = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
if (cmp >= 0)
PG_RETURN_BOOL(true);
else
@@ -115,6 +123,8 @@
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
int cmp = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
if (cmp == 0)
PG_RETURN_BOOL(true);
else
@@ -130,5 +140,8 @@
{
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
- PG_RETURN_INT32(gserialized_cmp(g1, g2));
+ int ret = gserialized_cmp(g1, g2);
+ PG_FREE_IF_COPY(g1, 0);
+ PG_FREE_IF_COPY(g2, 1);
+ PG_RETURN_INT32(ret);
}
More information about the postgis-tickets
mailing list