From 3cb2830e13d0d735850109628134e35a447d344b Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 4 Mar 2015 19:49:36 +0000 Subject: [PATCH] Be (slightly) more memory friendly when generating statistics git-svn-id: http://svn.osgeo.org/postgis/trunk@13303 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/gserialized_estimate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c index 4d2e187f8..a8829a837 100644 --- a/postgis/gserialized_estimate.c +++ b/postgis/gserialized_estimate.c @@ -1299,6 +1299,7 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu GBOX gbox; ND_BOX *nd_box; bool is_null; + bool is_copy; datum = fetchfunc(stats, i, &is_null); @@ -1312,6 +1313,7 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu /* Read the bounds from the gserialized. */ geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum); + is_copy = VARATT_IS_EXTENDED(datum); if ( LW_FAILURE == gserialized_get_gbox_p(geom, &gbox) ) { /* Skip empties too. */ @@ -1363,6 +1365,10 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu /* Increment our "good feature" count */ notnull_cnt++; + + /* Free up memory if our sample geometry was copied */ + if ( is_copy ) + pfree(geom); /* Give backend a chance of interrupting us */ vacuum_delay_point(); -- 2.50.1