From 092c68855c880d08dbaeddb0fd790afb60ce3d12 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Wed, 29 Jul 2020 11:54:49 -1000 Subject: [PATCH] Do not let the API object for the assembled grid live one GMT_Read_Data assigns a new object number to what is read, but for tiles it calls gmt_assemble_grid which also creates an object to pass to grdblend. However, once we get it back from grdblend we only want to keep the grid and discard the container since GMT_Read_Data already has a container for it. --- src/gmt_api.c | 21 +++++++++++++++++++++ src/gmt_internals.h | 1 + src/gmt_remote.c | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/src/gmt_api.c b/src/gmt_api.c index a1b917ac634..3c4e94f04ff 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -7564,6 +7564,27 @@ int GMT_Close_VirtualFile_ (unsigned int *family, char *string, int len) { } #endif +int gmtlib_delete_virtualfile (void *V_API, const char *string) { + /* Given a VirtualFile name, delete its record bu NULLing it */ + int object_ID, item; + struct GMTAPI_DATA_OBJECT *S_obj = NULL; + struct GMTAPI_CTRL *API = NULL; + if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION); + if (string == NULL) return_error (V_API, GMT_PTR_IS_NULL); + if ((object_ID = gmtapi_decode_id (string)) == GMT_NOTSET) + return_error (V_API, GMT_OBJECT_NOT_FOUND); + API = gmtapi_get_api_ptr (V_API); + if ((item = gmtlib_validate_id (API, GMT_NOTSET, object_ID, GMT_NOTSET, GMT_NOTSET)) == GMT_NOTSET) + return_error (API, GMT_OBJECT_NOT_FOUND); + S_obj = API->object[item]; /* Short-hand */ + if (S_obj->family != S_obj->actual_family) /* Reset the un-masquerading that GMT_Open_VirtualFile did */ + S_obj->family = S_obj->actual_family; + S_obj->no_longer_owner = true; + S_obj->resource = NULL; + + return GMT_NOERROR; +} + void * GMT_Read_VirtualFile (void *V_API, const char *string) { /* Given a VirtualFile name, retrieve the resulting object */ int object_ID; diff --git a/src/gmt_internals.h b/src/gmt_internals.h index f47ab9cc169..18f83c28066 100644 --- a/src/gmt_internals.h +++ b/src/gmt_internals.h @@ -52,6 +52,7 @@ struct GMT_XINGS { EXTERN_MSC char *dlerror (void); #endif +EXTERN_MSC int gmtlib_delete_virtualfile (void *API, const char *string); EXTERN_MSC bool gmtlib_file_lock (struct GMT_CTRL *GMT, int fd); EXTERN_MSC bool gmtlib_file_unlock (struct GMT_CTRL *GMT, int fd); EXTERN_MSC int gmtlib_file_is_jpeg2000_tile (struct GMTAPI_CTRL *API, char *file); diff --git a/src/gmt_remote.c b/src/gmt_remote.c index 866897ca0f2..5d2a4c8d3b9 100644 --- a/src/gmt_remote.c +++ b/src/gmt_remote.c @@ -1558,6 +1558,11 @@ struct GMT_GRID *gmtlib_assemble_tiles (struct GMTAPI_CTRL *API, double *region, GMT_Report (API, GMT_MSG_ERROR, "ERROR - Unable to receive blended grid from grdblend\n"); return NULL; } + if (gmtlib_delete_virtualfile (API, grid)) { /* Remove trace since passed upwards anyway */ + GMT_Report (API, GMT_MSG_ERROR, "ERROR - Unable to destroy temporary object for assembled grid\n"); + return NULL; + } + HH = gmt_get_H_hidden (G->header); HH->orig_datatype = GMT_SHORT; /* Since we know this */ return (G);