]> granicus.if.org Git - postgis/commitdiff
Avoid memory exhaustion when building a btree index (references #4004)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 26 Jan 2018 12:43:51 +0000 (12:43 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 26 Jan 2018 12:43:51 +0000 (12:43 +0000)
From Edmund Horner

git-svn-id: http://svn.osgeo.org/postgis/trunk@16360 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography_btree.c

index af9785910c67acad74aa9a3ac6c4d761e963837e..9b0d8896cbaa065ac76edf3605d5499937206829 100644 (file)
@@ -51,6 +51,8 @@ Datum geography_lt(PG_FUNCTION_ARGS)
        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 @@ Datum geography_le(PG_FUNCTION_ARGS)
        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 @@ Datum geography_gt(PG_FUNCTION_ARGS)
        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 @@ Datum geography_ge(PG_FUNCTION_ARGS)
        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 @@ Datum geography_eq(PG_FUNCTION_ARGS)
        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 @@ Datum geography_cmp(PG_FUNCTION_ARGS)
 {
        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);
 }