From 3c450186fd6bdfac9fba46e783e26b17b6474060 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 22 Dec 2011 05:48:52 +0000 Subject: [PATCH] Move SPI_finish to after elog calls. This seems to fix the regression failure in 877, though why is not clear. Is SPI_finish removing a memory context that palloc has allocated things inside? This would explain the odd result (tbl and col variables get emptied upon call to SPI_finish). git-svn-id: http://svn.osgeo.org/postgis/trunk@8498 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/geometry_estimate.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/postgis/geometry_estimate.c b/postgis/geometry_estimate.c index a0ea96207..1f5a59e31 100644 --- a/postgis/geometry_estimate.c +++ b/postgis/geometry_estimate.c @@ -1408,8 +1408,8 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) SPIcode = SPI_exec(query, 1); if (SPIcode != SPI_OK_SELECT) { - SPI_finish(); elog(ERROR, "geometry_estimated_extent: couldn't execute permission check sql via SPI"); + SPI_finish(); PG_RETURN_NULL(); } @@ -1419,8 +1419,8 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) if (!DatumGetBool(SPI_getbinval(tuple, tupdesc, 1, &isnull))) { - SPI_finish(); elog(ERROR, "geometry_estimated_extent: permission denied for relation %s", tbl); + SPI_finish(); PG_RETURN_NULL(); } @@ -1440,23 +1440,22 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) SPIcode = SPI_exec(query, 1); if (SPIcode != SPI_OK_SELECT ) { - SPI_finish(); elog(ERROR,"geometry_estimated_extent: couldnt execute sql via SPI"); + SPI_finish(); PG_RETURN_NULL(); } if (SPI_processed != 1) { - SPI_finish(); POSTGIS_DEBUGF(3, " %d stat rows", SPI_processed); /* * TODO: distinguish between empty and not analyzed ? */ - elog(WARNING, "No stats for \"%s\".\"%s\".\"%s\" " - "(empty or not analyzed)", + elog(WARNING, "No stats for \"%s\".\"%s\".\"%s\" (empty or not analyzed)", ( nsp ? nsp : "" ), tbl, col); + SPI_finish(); PG_RETURN_NULL() ; } @@ -1466,12 +1465,12 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS) array = DatumGetArrayTypeP(SPI_getbinval(tuple, tupdesc, 1, &isnull)); if (isnull) { - SPI_finish(); POSTGIS_DEBUG(3, " stats are NULL"); elog(ERROR, "geometry_estimated_extent: null statistics for table"); + SPI_finish(); PG_RETURN_NULL(); } if ( ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array)) != 4 ) -- 2.40.0