From ccfdb537f75386aa38db18660f14f0dc41b54ed8 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Wed, 3 Feb 2010 02:13:08 +0000 Subject: [PATCH] Better error checking for elev and sat plugins --- src/plugins/elev.c | 25 +++++++++++++++++++++---- src/plugins/sat.c | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/plugins/elev.c b/src/plugins/elev.c index adb25ee..4c28847 100644 --- a/src/plugins/elev.c +++ b/src/plugins/elev.c @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -25,6 +26,7 @@ #define MAX_RESOLUTION 500 #define TILE_WIDTH 1024 #define TILE_HEIGHT 512 +#define TILE_SIZE (TILE_WIDTH*TILE_HEIGHT*sizeof(guint16)) struct _TileData { /* OpenGL has to be first to make gis_opengl_render_tiles happy */ @@ -99,9 +101,16 @@ struct _LoadTileData { }; static guint16 *_load_bil(gchar *path) { - gchar *data; - g_file_get_contents(path, &data, NULL, NULL); + gsize len; + gchar *data = NULL; + g_file_get_contents(path, &data, &len, NULL); g_debug("GisPluginElev: load_bil %p", data); + if (len != TILE_SIZE) { + g_warning("GisPluginElev: _load_bil - unexpected tile size %d, != %d", + len, TILE_SIZE); + g_free(data); + return NULL; + } return (guint16*)data; } static GdkPixbuf *_load_pixbuf(guint16 *bil) @@ -191,10 +200,18 @@ static void _load_tile(GisTile *tile, gpointer _self) load->self = self; load->tile = tile; load->data = g_new0(struct _TileData, 1); - if (LOAD_BIL || LOAD_OPENGL) + if (LOAD_BIL || LOAD_OPENGL) { load->data->bil = _load_bil(load->path); - if (LOAD_OPENGL) + if (!load->data->bil) { + g_remove(load->path); + g_free(load->path); + g_free(load); + return; + } + } + if (LOAD_OPENGL) { load->pixbuf = _load_pixbuf(load->data->bil); + } g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, load, NULL); } diff --git a/src/plugins/sat.c b/src/plugins/sat.c index 155b30c..d65f833 100644 --- a/src/plugins/sat.c +++ b/src/plugins/sat.c @@ -82,6 +82,7 @@ static void _load_tile(GisTile *tile, gpointer _self) g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL); } else { g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path); + g_free(data); g_remove(path); } g_free(path); -- 2.43.2