From 037480f70b4f7450e5580dab556ce05c53c17c4c Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Sat, 15 Oct 2016 21:16:04 +0000 Subject: [PATCH] raster GUC - boot_postgis_gdal_enabled_drivers should use TopMemoryContext instead of CurrentMemoryContext References #3659 for trunk (PostGIS 2.4) git-svn-id: http://svn.osgeo.org/postgis/trunk@15208 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_pg/rtpostgis.c | 46 +++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c index 1ae987902..215fa6edd 100644 --- a/raster/rt_pg/rtpostgis.c +++ b/raster/rt_pg/rtpostgis.c @@ -132,6 +132,7 @@ #include /* for palloc */ #include /* for PG_MODULE_MAGIC */ #include "utils/guc.h" +#include "utils/memutils.h" #include "../../postgis_config.h" #include "lwgeom_pg.h" @@ -151,6 +152,9 @@ PG_MODULE_MAGIC; /* Module load callback */ void _PG_init(void); +/* Module unload callback */ +void _PG_fini(void); + #define RT_MSG_MAXLEN 256 @@ -244,6 +248,14 @@ static char *gdal_datapath = NULL; extern char *gdal_enabled_drivers; extern char enable_outdb_rasters; +/* ---------------------------------------------------------------- */ +/* Useful variables */ +/* ---------------------------------------------------------------- */ + +static char *env_postgis_gdal_enabled_drivers = NULL; +static char *boot_postgis_gdal_enabled_drivers = NULL; +static char *env_postgis_enable_outdb_rasters = NULL; + /* postgis.gdal_datapath */ static void rtpg_assignHookGDALDataPath(const char *newpath, void *extra) { @@ -408,11 +420,14 @@ rtpg_assignHookEnableOutDBRasters(bool enable, void *extra) { void _PG_init(void) { - char *env_postgis_gdal_enabled_drivers = NULL; - char *boot_postgis_gdal_enabled_drivers = NULL; - - char *env_postgis_enable_outdb_rasters = NULL; bool boot_postgis_enable_outdb_rasters = false; + MemoryContext old_context; + + /* + * Change to context for memory allocation calls like palloc() in the + * extension initialization routine + */ + old_context = MemoryContextSwitchTo(TopMemoryContext); /* use POSTGIS_GDAL_ENABLED_DRIVERS to set the bootValue @@ -543,8 +558,29 @@ _PG_init(void) { ); } - /* free memory allocations */ + /* Revert back to old context */ + MemoryContextSwitchTo(old_context); +} + +/* Module unload callback */ +void +_PG_fini(void) { + + MemoryContext old_context; + + old_context = MemoryContextSwitchTo(TopMemoryContext); + + /* Clean up */ + pfree(env_postgis_gdal_enabled_drivers); pfree(boot_postgis_gdal_enabled_drivers); + pfree(env_postgis_enable_outdb_rasters); + + env_postgis_gdal_enabled_drivers = NULL; + boot_postgis_gdal_enabled_drivers = NULL; + env_postgis_enable_outdb_rasters = NULL; + + /* Revert back to old context */ + MemoryContextSwitchTo(old_context); }