[postgis-tickets] r15209 - raster GUC - boot_postgis_gdal_enabled_drivers should use TopMemoryContext instead of CurrentMemoryContext

Regina Obe lr at pcorp.us
Sat Oct 15 18:16:43 PDT 2016


Author: robe
Date: 2016-10-15 18:16:42 -0700 (Sat, 15 Oct 2016)
New Revision: 15209

Modified:
   branches/2.3/raster/rt_pg/rtpostgis.c
Log:
raster GUC - boot_postgis_gdal_enabled_drivers should use TopMemoryContext instead of CurrentMemoryContext
References #3659  for 2.3 (PostGIS 2.3.4) patch provided by manaeem

Modified: branches/2.3/raster/rt_pg/rtpostgis.c
===================================================================
--- branches/2.3/raster/rt_pg/rtpostgis.c	2016-10-15 21:16:04 UTC (rev 15208)
+++ branches/2.3/raster/rt_pg/rtpostgis.c	2016-10-16 01:16:42 UTC (rev 15209)
@@ -132,6 +132,7 @@
 #include <postgres.h> /* for palloc */
 #include <fmgr.h> /* for PG_MODULE_MAGIC */
 #include "utils/guc.h"
+#include "utils/memutils.h"
 
 #include "../../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -151,6 +152,9 @@
 /* Module load callback */
 void _PG_init(void);
 
+/* Module unload callback */
+void _PG_fini(void);
+
 #define RT_MSG_MAXLEN 256
 
 
@@ -244,6 +248,14 @@
 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,13 +420,16 @@
 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
 	 of GUC postgis.gdal_enabled_drivers
 	*/
@@ -543,8 +558,29 @@
 		);
 	}
 
-	/* 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);
 }
 
 



More information about the postgis-tickets mailing list