]> granicus.if.org Git - postgis/commitdiff
#1504 (Segfault running ST_EstimatedExtent())
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 27 Jan 2012 22:24:44 +0000 (22:24 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 27 Jan 2012 22:24:44 +0000 (22:24 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8950 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geometry_estimate.c

index 80040914f2fef4deeff5dabb8d75126a003dcff2..41dd64da7e6e102993b2af2b5b276ff4ca669b4b 100644 (file)
@@ -1335,6 +1335,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
        size_t querysize;
        GEOM_STATS geomstats;
        float reltuples;
+       Datum binval;
 
        if ( PG_NARGS() == 3 )
        {
@@ -1478,7 +1479,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
        tuple = tuptable->vals[0];
 
        /* Check if the table has zero rows first */
-       reltuples = DatumGetFloat4(SPI_getbinval(tuple, tupdesc, 2, &isnull));
+       binval = SPI_getbinval(tuple, tupdesc, 2, &isnull);
        if (isnull)
        {
 
@@ -1489,6 +1490,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
                SPI_finish();
                PG_RETURN_NULL();
        }
+       reltuples = DatumGetFloat4(binval);
        if ( ! reltuples )
        {
                POSTGIS_DEBUG(3, "table has estimated zero rows");
@@ -1503,7 +1505,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       array = DatumGetArrayTypeP(SPI_getbinval(tuple, tupdesc, 1, &isnull));
+       binval = SPI_getbinval(tuple, tupdesc, 1, &isnull);
        if (isnull)
        {
 
@@ -1514,6 +1516,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
                SPI_finish();
                PG_RETURN_NULL();
        }
+       array = DatumGetArrayTypeP(binval);
        if ( ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array)) != 4 )
        {
                elog(ERROR, " corrupted histogram");