[postgis-tickets] r15210 - raster GUC - boot_postgis_gdal_enabled_drivers should use TopMemoryContext instead of CurrentMemoryContext
Regina Obe
lr at pcorp.us
Sat Oct 15 22:36:26 PDT 2016
Author: robe
Date: 2016-10-15 22:36:26 -0700 (Sat, 15 Oct 2016)
New Revision: 15210
Modified:
branches/2.2/NEWS
branches/2.2/raster/rt_pg/rtpostgis.c
Log:
raster GUC - boot_postgis_gdal_enabled_drivers should use TopMemoryContext instead of CurrentMemoryContext
Closes #3659 for 2.2 (PostGIS 2.2.4) patch provided by manaeem
Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS 2016-10-16 01:16:42 UTC (rev 15209)
+++ branches/2.2/NEWS 2016-10-16 05:36:26 UTC (rev 15210)
@@ -4,6 +4,8 @@
* Bug Fixes *
- #3656, Fix upgrade of aggregates from 2.2 or lower version
+ - #3659, Crash caused by raster GUC define after CREATE EXTENSION
+ using wrong memory context. (manaeem)
PostGIS 2.2.3
Modified: branches/2.2/raster/rt_pg/rtpostgis.c
===================================================================
--- branches/2.2/raster/rt_pg/rtpostgis.c 2016-10-16 01:16:42 UTC (rev 15209)
+++ branches/2.2/raster/rt_pg/rtpostgis.c 2016-10-16 05:36:26 UTC (rev 15210)
@@ -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,11 +420,8 @@
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;
/* Install liblwgeom handlers */
pg_install_lwgeom_handlers();
@@ -421,6 +430,12 @@
rt_set_handlers(rt_pg_alloc, rt_pg_realloc, rt_pg_free, rt_pg_error, rt_pg_debug, rt_pg_notice);
/*
+ * 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
*/
@@ -513,6 +528,27 @@
NULL /* GucShowHook show_hook */
);
- /* 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