From 89e6835186d699673c0b449940453e64404e8388 Mon Sep 17 00:00:00 2001 From: Jeff Larson Date: Tue, 25 Jun 2019 23:51:08 -0700 Subject: [PATCH] Oh wow. A bunch of regrets here: 1. Use specific methods, like `OSRDestroySpatialReference`, over generic ones, like `OSRRelease`. The specific ones are always right. 2. `atexit` is always a mistake. 3. Questions end with a question mark. --- src/init.c | 8 ++------ src/map.c | 4 ++-- src/query.c | 1 + src/vector_layer.c | 3 --- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/init.c b/src/init.c index 1943a1b..fe613da 100644 --- a/src/init.c +++ b/src/init.c @@ -5,20 +5,16 @@ static int initialized = 0; -// The atexit handler used to close all connections to open data stores -static void cleanup() { - OGRCleanupAll(); -} - // Initialize libraries, register the atexit handler and set up error reporting. void simplet_init() { if (initialized) return; CPLSetConfigOption("OGR_ENABLE_PARTIAL_REPROJECTION", "ON"); #ifdef DEBUG CPLSetConfigOption("CPL_DEBUG", "ON"); +#else + CPLSetConfigOption("CPL_DEBUG", "OFF"); #endif OGRRegisterAll(); GDALAllRegister(); - atexit(cleanup); initialized = 1; }; diff --git a/src/map.c b/src/map.c index 775d83d..c13e481 100644 --- a/src/map.c +++ b/src/map.c @@ -59,7 +59,7 @@ void simplet_map_free(simplet_map_t *map) { simplet_list_free(map->layers); } - if (map->proj) OSRRelease(map->proj); + if (map->proj) OSRDestroySpatialReference(map->proj); if (map->bgcolor) free(map->bgcolor); @@ -248,7 +248,7 @@ const char *simplet_map_status_to_string(simplet_map_t *map) { // Check if the map is valid for rendering simplet_status_t simplet_map_is_valid(simplet_map_t *map) { - // Does it have a previously set error. + // Does it have a previously set error? if (!(map->status == SIMPLET_OK)) return SIMPLET_ERR; // Does it have a bounds? diff --git a/src/query.c b/src/query.c index c4827f2..514a50f 100644 --- a/src/query.c +++ b/src/query.c @@ -216,6 +216,7 @@ simplet_status_t simplet_query_process(simplet_query_t *query, if (!(olayer = OGR_DS_ExecuteSQL(source, query->ogrsql, NULL, NULL))) { int err = CPLGetLastErrorNo(); if (!err) { + // FIXME: This should be a problem, but it is ignored right now. return SIMPLET_OK; } else { return set_error(query, SIMPLET_OGR_ERR, CPLGetLastErrorMsg()); diff --git a/src/vector_layer.c b/src/vector_layer.c index 570cfb4..71e3e90 100644 --- a/src/vector_layer.c +++ b/src/vector_layer.c @@ -80,9 +80,6 @@ simplet_status_t simplet_vector_layer_process(simplet_vector_layer_t *layer, if (!(source = OGROpenShared(layer->source, 0, NULL))) return set_error(layer, SIMPLET_OGR_ERR, "error opening layer source"); - // Retain the datasource because we want to cache open connections to a - // data source like postgres. - if (OGR_DS_GetRefCount(source) == 1) OGR_DS_Reference(source); if (!(iter = simplet_get_list_iter(layer->queries))) { OGRReleaseDataSource(source); return set_error(layer, SIMPLET_OOM, "out of memory getting list iterator");