Skip to content

Commit b169019

Browse files
authored
Fix another bunch of CIDs (#4276)
* Fix another bunch of CIDs * Use snprintf
1 parent 4dd2b5a commit b169019

22 files changed

+130
-51
lines changed

src/clear.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ static int clear_data (struct GMTAPI_CTRL *API, char *planet) {
114114
sprintf (current_d3, "%s/%s/%s/%s", server_dir, dir1[d1], dir2[d2], dir3[d3]); /* E.g., ~/.gmt/server/earth/earth_relief/earth_relief_15s_p */
115115
if (gmt_remove_dir (API, current_d3, false)) {
116116
GMT_Report (API, GMT_MSG_ERROR, "Unable to remove directory %s [permissions?]\n", current_d3);
117+
gmtlib_free_dir_list (GMT, &dir1);
118+
gmtlib_free_dir_list (GMT, &dir2);
117119
gmtlib_free_dir_list (GMT, &dir3);
118120
return GMT_NOERROR;
119121
}
@@ -123,6 +125,7 @@ static int clear_data (struct GMTAPI_CTRL *API, char *planet) {
123125
}
124126
if (gmt_remove_dir (API, current_d2, false)) {
125127
GMT_Report (API, GMT_MSG_ERROR, "Unable to remove directory %s [permissions?]\n", current_d2);
128+
gmtlib_free_dir_list (GMT, &dir1);
126129
gmtlib_free_dir_list (GMT, &dir2);
127130
return GMT_NOERROR;
128131
}
@@ -165,7 +168,7 @@ static int clear_sessions (struct GMTAPI_CTRL *API) {
165168
#ifdef _WIN32
166169
char* t = gmt_strrep(API->session_dir, "/", "\\"); /* rmdir needs paths with back-slashes */
167170
strcpy(del_cmd, "rmdir /s /q ");
168-
strcat(del_cmd, t);
171+
strncat(del_cmd, t, PATH_MAX-1);
169172
gmt_M_str_free(t);
170173
#else
171174
sprintf (del_cmd, "rm -rf %s", API->session_dir);
@@ -204,6 +207,7 @@ static int clear_geography (struct GMTAPI_CTRL *API, char *data) {
204207
sprintf (current_dir, "%s/%s", geography_dir, dir[d]); /* E.g., ~/.gmt/geography/gshhg */
205208
if (gmt_remove_dir (API, current_dir, false)) {
206209
GMT_Report (API, GMT_MSG_ERROR, "Unable to remove directory %s [permissions?]\n", current_dir);
210+
gmtlib_free_dir_list (GMT, &dir);
207211
return GMT_NOERROR;
208212
}
209213
d++;

src/geodesy/gpsgridder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ EXTERN_MSC int GMT_gpsgridder (void *V_API, int mode, void *args) {
614614
}
615615
if (In->data == NULL) {
616616
gmt_quit_bad_record (API, In);
617+
gmt_M_free (GMT, X); gmt_M_free (GMT, u); gmt_M_free (GMT, v);
617618
Return (API->error);
618619
}
619620

src/gmt_api.c

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ GMT_LOCAL char ** gmtapi_process_keys (void *V_API, const char *string, char typ
16361636
n = kk; /* May have lost some NULLs. Make a revised string for debug output */
16371637
for (k = 0; k < n; k++) {
16381638
strcat (revised, ",");
1639-
strcat (revised, s[k]);
1639+
strncat (revised, s[k], GMT_LEN64-1);
16401640
}
16411641
if (revised[0]) GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_process_keys: Revised keys string is %s\n", &revised[1]);
16421642
*n_items = (unsigned int)n; /* Total number of remaining keys for this module */
@@ -4068,7 +4068,7 @@ GMT_LOCAL int gmtapi_import_ppm_header (struct GMT_CTRL *GMT, char *fname, bool
40684068
return GMT_ERROR_ON_FOPEN;
40694069
}
40704070
while ((c = fgetc (fp)) != '\n' && k < GMT_LEN128) text[k++] = c; /* Get first record up to newline */
4071-
text[k] = '\0'; /* Terminate line */
4071+
text[MIN(k,GMT_LEN128-1)] = '\0'; /* Terminate line & check that we don't overflow */
40724072
if (text[1] == '5') /* Used P5 for grayscale image */
40734073
I->header->n_bands = 1;
40744074
else if (text[1] == '6') /* Used P6 for rgb image */
@@ -4086,7 +4086,7 @@ GMT_LOCAL int gmtapi_import_ppm_header (struct GMT_CTRL *GMT, char *fname, bool
40864086
ungetc (c, fp);
40874087
k = 0;
40884088
while ((c = fgetc (fp)) != '\n' && k < GMT_LEN128) text[k++] = c; /* Get next record up to newline */
4089-
text[k] = '\0'; /* Terminate line */
4089+
text[MIN(k,GMT_LEN128-1)] = '\0'; /* Terminate line & check that we don't overflow */
40904090
n = sscanf (text, "%d %d %d", &I->header->n_rows, &I->header->n_columns, &max);
40914091
if (n == 2) { /* Must skip past a separate record with the max pixel value */
40924092
while ((c = fgetc (fp)) != '\n' ) k++;
@@ -4524,14 +4524,20 @@ GMT_LOCAL int gmtapi_export_ppm (struct GMT_CTRL *GMT, char *fname, struct GMT_I
45244524
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Alpha-channel not supported by PPM format - ignored\n");
45254525
n = I->header->size * I->header->n_bands;
45264526
if (!strncmp (I->header->mem_layout, "TRP", 3U)) { /* Easy street! */
4527-
if (fwrite (I->data, sizeof(char), n, fp) != n) return GMT_IMAGE_WRITE_ERROR;
4527+
if (fwrite (I->data, sizeof(char), n, fp) != n) {
4528+
gmt_fclose (GMT, fp);
4529+
return GMT_IMAGE_WRITE_ERROR;
4530+
}
45284531
}
45294532
else { /* Must change image layout first as PPM is strictly TRP */
45304533
char *data = NULL;
45314534
GMT_Report (GMT->parent, GMT_MSG_VERBOSE, "Must convert image from %s to TRP in order to write PPM file\n", I->header->mem_layout);
45324535
if ((data = gmt_M_memory_aligned (GMT, NULL, n, char)) == NULL) {
45334536
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unable to allocate image memory in gmtapi_export_ppm to force TRP format - written as is\n");
4534-
if (fwrite (I->data, sizeof(char), n, fp) != n) return GMT_IMAGE_WRITE_ERROR;
4537+
if (fwrite (I->data, sizeof(char), n, fp) != n) {
4538+
gmt_fclose (GMT, fp);
4539+
return GMT_IMAGE_WRITE_ERROR;
4540+
}
45354541
}
45364542
else { /* Convert from TRB to TRP */
45374543
GMT_Change_Layout (GMT->parent, GMT_IS_IMAGE, "TRP", 0, I, data, NULL);
@@ -5367,7 +5373,7 @@ GMT_LOCAL struct GMT_MATRIX * gmtapi_read_matrix (struct GMT_CTRL *GMT, void *so
53675373
return (M);
53685374
}
53695375

5370-
GMT_LOCAL void * gmtapi_grid2matrix (struct GMTAPI_CTRL *API, struct GMT_GRID *In, struct GMT_MATRIX *Out) {
5376+
GMT_LOCAL void *gmtapi_grid2matrix (struct GMTAPI_CTRL *API, struct GMT_GRID *In, struct GMT_MATRIX *Out) {
53715377
bool alloc = (Out == NULL);
53725378
uint64_t row, col, ij, ij_M;
53735379
double d;
@@ -5821,7 +5827,7 @@ GMT_LOCAL int gmtapi_export_vector (struct GMTAPI_CTRL *API, int object_ID, unsi
58215827
return GMT_NOERROR;
58225828
}
58235829

5824-
GMT_LOCAL struct GMT_VECTOR * gmtapi_read_vector (struct GMT_CTRL *GMT, void *source, unsigned int src_type, unsigned int mode) {
5830+
GMT_LOCAL struct GMT_VECTOR *gmtapi_read_vector (struct GMT_CTRL *GMT, void *source, unsigned int src_type, unsigned int mode) {
58255831
/* We read the VECTOR from fp [or stdin].
58265832
* src_type can be GMT_IS_[FILE|STREAM|FDESC]
58275833
* mode is not used yet. We only do ascii file for now - later need to deal with -b
@@ -6298,8 +6304,10 @@ GMT_LOCAL int gmtapi_init_import (struct GMTAPI_CTRL *API, enum GMT_enum_family
62986304
gmt_M_memcpy (wesn, API->GMT->common.R.wesn, 4U, double);
62996305
}
63006306
}
6301-
if ((object_ID = GMT_Register_IO (API, family|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, geometry, GMT_IN, wesn, current->arg)) == GMT_NOTSET)
6307+
if ((object_ID = GMT_Register_IO (API, family|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, geometry, GMT_IN, wesn, current->arg)) == GMT_NOTSET) {
6308+
gmt_M_free (API->GMT, wesn);
63026309
return_value (API, API->error, GMT_NOTSET); /* Failure to register */
6310+
}
63036311
n_reg++; /* Count of new items registered */
63046312
gmt_M_free (API->GMT, wesn);
63056313
if (first_ID == GMT_NOTSET) first_ID = object_ID; /* Found our first ID */
@@ -7921,9 +7929,11 @@ void * GMT_Read_Data (void *V_API, unsigned int family, unsigned int method, uns
79217929
if (infile) input = strdup (infile);
79227930
API = gmtapi_get_api_ptr (V_API);
79237931
API->error = GMT_NOERROR;
7924-
just_get_data = (gmt_M_file_is_memory (input)); /* A regular GMT resource passed via memory */
7925-
if (just_get_data && gmtapi_M_is_output (input)) /* A virtual output file created elsewhere, retrieve and we are done */
7932+
just_get_data = (gmt_M_file_is_memory (input)); /* A regular GMT resource passed via memory */
7933+
if (just_get_data && gmtapi_M_is_output (input)) { /* A virtual output file created elsewhere, retrieve and we are done */
7934+
gmt_M_str_free (input);
79267935
return (GMT_Read_VirtualFile (API, input));
7936+
}
79277937
reset = (mode & GMT_IO_RESET); /* We want to reset resource as unread after reading it */
79287938
if (reset) mode -= GMT_IO_RESET;
79297939
module_input = (family & GMT_VIA_MODULE_INPUT); /* Are we reading a resource that should be considered a module input? */
@@ -8085,6 +8095,7 @@ void * GMT_Read_Data (void *V_API, unsigned int family, unsigned int method, uns
80858095
}
80868096
if ((new_obj = gmtapi_get_data (API, in_ID, mode, data)) == NULL) {
80878097
if (reg_here) gmtlib_unregister_io (API, in_ID, GMT_IN); /* Since reading failed */
8098+
gmt_M_str_free (input); /* Done with this variable) */
80888099
return_null (API, API->error);
80898100
}
80908101
if (reset) API->object[item]->status = 0; /* Reset to unread */
@@ -9154,7 +9165,10 @@ GMT_LOCAL int gmtapi_put_record_init (struct GMTAPI_CTRL *API, unsigned int mode
91549165
return_error (API, GMT_MEMORY_ERROR);
91559166
for (col = 0; col < V_obj->n_columns; col++) /* Set same export data type for all vectors */
91569167
V_obj->type[col] = GMT->current.setting.export_type;
9157-
if ((error = gmtlib_alloc_vectors (GMT, V_obj, S_obj->n_alloc)) != GMT_NOERROR) return (gmtlib_report_error (API, error));
9168+
if ((error = gmtlib_alloc_vectors (GMT, V_obj, S_obj->n_alloc)) != GMT_NOERROR) {
9169+
/* Have to free V_obj here */
9170+
return (gmtlib_report_error (API, error));
9171+
}
91589172
if (record->text) V_obj->text = gmt_M_memory (GMT, NULL, S_obj->n_alloc, char *);
91599173
S_obj->resource = V_obj; /* Save so we can get it next time */
91609174
}
@@ -12544,7 +12558,7 @@ GMT_LOCAL void * gmtapi_dataset2dataset (struct GMTAPI_CTRL *API, struct GMT_DAT
1254412558
return Out;
1254512559
}
1254612560

12547-
GMT_LOCAL void * gmtapi_dataset2matrix (struct GMTAPI_CTRL *API, struct GMT_DATASET *In, struct GMT_MATRIX *Out, unsigned int header, unsigned int mode) {
12561+
GMT_LOCAL void *gmtapi_dataset2matrix (struct GMTAPI_CTRL *API, struct GMT_DATASET *In, struct GMT_MATRIX *Out, unsigned int header, unsigned int mode) {
1254812562
/* Convert a dataset to a matrix.
1254912563
* If Out is not NULL then we assume it has enough rows and columns to hold the dataset records.
1255012564
* Header controls if segment headers are written as NaN recs
@@ -12572,8 +12586,14 @@ GMT_LOCAL void * gmtapi_dataset2matrix (struct GMTAPI_CTRL *API, struct GMT_DATA
1257212586
MH = gmt_get_M_hidden (Out);
1257312587
MH->alloc_mode = GMT_ALLOC_INTERNALLY;
1257412588
}
12575-
if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) return (NULL);
12576-
if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL) return (NULL);
12589+
if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) {
12590+
gmt_M_free (GMT, Out);
12591+
return (NULL);
12592+
}
12593+
if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL) {
12594+
gmt_M_free (GMT, Out);
12595+
return (NULL);
12596+
}
1257712597
for (tbl = row_out = 0; tbl < In->n_tables; tbl++) {
1257812598
D = In->table[tbl]; /* Shorthand to current input data table */
1257912599
for (seg = 0; seg < D->n_segments; seg++) {
@@ -12618,7 +12638,10 @@ GMT_LOCAL void * gmtapi_dataset2vector (struct GMTAPI_CTRL *API, struct GMT_DATA
1261812638
return (NULL);
1261912639
}
1262012640
}
12621-
if ((api_put_val = gmtapi_select_put_function (API, Out->type[0])) == NULL) return NULL; /* Since all columns are of same type we get the pointer here */
12641+
if ((api_put_val = gmtapi_select_put_function (API, Out->type[0])) == NULL) { /* Since all columns are of same type we get the pointer here */
12642+
gmt_M_free (GMT, Out);
12643+
return NULL;
12644+
}
1262212645
for (tbl = row_out = 0; tbl < In->n_tables; tbl++) {
1262312646
D = In->table[tbl]; /* Shorthand to current input data table */
1262412647
for (seg = 0; seg < D->n_segments; seg++) {
@@ -12769,10 +12792,14 @@ GMT_LOCAL void * gmtapi_vector2matrix (struct GMTAPI_CTRL *API, struct GMT_VECTO
1276912792
MH->alloc_mode = GMT_ALLOC_INTERNALLY;
1277012793
}
1277112794

12772-
if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL)
12795+
if ((GMT_2D_to_index = gmtapi_get_2d_to_index (API, Out->shape, GMT_GRID_IS_REAL)) == NULL) {
12796+
gmt_M_free (GMT, Out);
1277312797
return (NULL);
12774-
if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) /* Since all columns are of same type we get the pointer here */
12798+
}
12799+
if ((api_put_val = gmtapi_select_put_function (API, Out->type)) == NULL) { /* Since all columns are of same type we get the pointer here */
12800+
gmt_M_free (GMT, Out);
1277512801
return (NULL);
12802+
}
1277612803
for (col = 0; col < In->n_columns; col++) {
1277712804
if ((api_get_val = gmtapi_select_get_function (API, In->type[col])) == NULL) {
1277812805
gmt_M_free (GMT, Out);
@@ -12793,7 +12820,7 @@ GMT_LOCAL void * gmtapi_vector2matrix (struct GMTAPI_CTRL *API, struct GMT_VECTO
1279312820
#define GMT_TYPE_MODE 1
1279412821
#define GMT_FORMAT_MODE 1 /* Same as GMT_TYPE_MODE [not a typo] */
1279512822

12796-
void * GMT_Convert_Data (void *V_API, void *In, unsigned int family_in, void *Out, unsigned int family_out, unsigned int flag[]) {
12823+
void *GMT_Convert_Data (void *V_API, void *In, unsigned int family_in, void *Out, unsigned int family_out, unsigned int flag[]) {
1279712824
/* Convert between valid pairs of objects, If Out == NULL then we allocate an output object,
1279812825
* otherwise we assume we are given adequate space already. This is most likely restricted to a GMT_MATRIX.
1279912826
* flag is an array with two unsigned integers controlling various aspects of the conversion:
@@ -13243,7 +13270,7 @@ GMT_LOCAL int gmtapi_change_imagelayout (struct GMTAPI_CTRL *API, char *code, un
1324313270
}
1324413271

1324513272
if (changed) { /* Update the mem_layout for this image */
13246-
strncpy (I->header->mem_layout, code, strlen(code));
13273+
strncpy (I->header->mem_layout, code, MIN(strlen(code),4));
1324713274
if (I->alpha) I->header->mem_layout[3] = 'a'; /* Flag that we have transparency */
1324813275
}
1324913276

@@ -13800,7 +13827,7 @@ int GMT_Get_FilePath (void *V_API, unsigned int family, unsigned int direction,
1380013827
if ((mode & GMT_FILE_CHECK) == 0) { /* Pass the local path back */
1380113828
GMT_Report (API, GMT_MSG_DEBUG, "Replace file %s with %s\n", file, local_path);
1380213829
if (c) /* Also append any file directives via modifiers */
13803-
strcat (local_path, c);
13830+
strncat (local_path, c, PATH_MAX-1);
1380413831
gmt_M_str_free (*file_ptr);
1380513832
*file_ptr = strdup (local_path);
1380613833
}

src/gmt_dcw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,9 @@ unsigned int gmt_DCW_list (struct GMT_CTRL *GMT, struct GMT_DCW_SELECT *F) {
741741
uint64_t dim[4] = {1, 1, row, 0};
742742
if ((D = GMT_Create_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_TEXT, GMT_WITH_STRINGS, dim, NULL, NULL, 0, 0, NULL)) == NULL) {
743743
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unable to make data set for country listing!\n");
744+
gmt_M_free (GMT, GMT_DCW_country);
745+
gmt_M_free (GMT, GMT_DCW_state);
746+
gmt_M_free (GMT, GMT_DCW_country_with_state);
744747
return GMT_RUNTIME_ERROR;
745748
}
746749
S = D->table[0]->segment[0]; /* The one and only segment in this table */
@@ -749,6 +752,9 @@ unsigned int gmt_DCW_list (struct GMT_CTRL *GMT, struct GMT_DCW_SELECT *F) {
749752

750753
if (GMT_Write_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_TEXT, GMT_WRITE_NORMAL, NULL, NULL, D) != GMT_NOERROR) {
751754
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Unable to write data set for country listing to stdout!\n");
755+
gmt_M_free (GMT, GMT_DCW_country);
756+
gmt_M_free (GMT, GMT_DCW_state);
757+
gmt_M_free (GMT, GMT_DCW_country_with_state);
752758
return GMT_RUNTIME_ERROR;
753759
}
754760

src/gmt_esri_io.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ GMT_LOCAL int gmtesriio_read_info (struct GMT_CTRL *GMT, FILE *fp, struct GMT_GR
259259
}
260260
else if ((HH->flags[0] == 'L' || HH->flags[0] == 'B') && HH->flags[1] == '2') { /* A Arc/Info BINARY file */
261261
if ((fp2 = gmt_fopen (GMT, header->title, "r")) == NULL) {
262-
gmt_fclose (GMT, fp);
263262
return (GMT_GRDIO_OPEN_FAILED);
264263
}
265264
/* To use the same parsing header code as in the ASCII file case where header and data are in the
@@ -272,21 +271,18 @@ GMT_LOCAL int gmtesriio_read_info (struct GMT_CTRL *GMT, FILE *fp, struct GMT_GR
272271
if (sscanf (record, "%*s %d", &header->n_columns) != 1) {
273272
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Arc/Info ASCII Grid: Error decoding ncols record\n");
274273
if (fpBAK) gmt_fclose (GMT, fp2);
275-
gmt_fclose (GMT, fp);
276274
return (GMT_GRDIO_READ_FAILED);
277275
}
278276
gmt_fgets (GMT, record, GMT_BUFSIZ, fp);
279277
if (sscanf (record, "%*s %d", &header->n_rows) != 1) {
280278
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Arc/Info ASCII Grid: Error decoding nrows record\n");
281279
if (fpBAK) gmt_fclose (GMT, fp2);
282-
gmt_fclose (GMT, fp);
283280
return (GMT_GRDIO_READ_FAILED);
284281
}
285282
gmt_fgets (GMT, record, GMT_BUFSIZ, fp);
286283
if (sscanf (record, "%*s %lf", &header->wesn[XLO]) != 1) {
287284
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Arc/Info ASCII Grid: Error decoding xll record\n");
288285
if (fpBAK) gmt_fclose (GMT, fp2);
289-
gmt_fclose (GMT, fp);
290286
return (GMT_GRDIO_READ_FAILED);
291287
}
292288
gmt_str_tolower (record);
@@ -295,7 +291,6 @@ GMT_LOCAL int gmtesriio_read_info (struct GMT_CTRL *GMT, FILE *fp, struct GMT_GR
295291
if (sscanf (record, "%*s %lf", &header->wesn[YLO]) != 1) {
296292
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Arc/Info ASCII Grid: Error decoding yll record\n");
297293
if (fpBAK) gmt_fclose (GMT, fp2);
298-
gmt_fclose (GMT, fp);
299294
return (GMT_GRDIO_READ_FAILED);
300295
}
301296
gmt_str_tolower (record);
@@ -304,7 +299,6 @@ GMT_LOCAL int gmtesriio_read_info (struct GMT_CTRL *GMT, FILE *fp, struct GMT_GR
304299
if (sscanf (record, "%*s %lf", &header->inc[GMT_X]) != 1) {
305300
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Arc/Info ASCII Grid: Error decoding cellsize record\n");
306301
if (fpBAK) gmt_fclose (GMT, fp2);
307-
gmt_fclose (GMT, fp);
308302
return (GMT_GRDIO_READ_FAILED);
309303
}
310304
/* Handle the optional nodata_value record */

src/gmt_gdalread.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ int gmt_gdalread (struct GMT_CTRL *GMT, char *gdal_filename, struct GMT_GDALREAD
835835

836836
if (error) {
837837
GMT_Report (GMT->parent, GMT_MSG_ERROR, "gmt_gdalread failed to extract a Sub-region\n");
838+
gmt_M_free (GMT, whichBands);
838839
return (-1);
839840
}
840841

src/gmt_gdalwrite.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int gmt_gdalwrite (struct GMT_CTRL *GMT, char *fname, struct GMT_GDALWRITE_CTRL
282282
GDALColorEntry sEntry;
283283
GDALProgressFunc pfnProgress = GDALTermProgress;
284284

285-
int n_cols, n_rows, i;
285+
int n_cols, n_rows, i, error = GMT_NOERROR;
286286
int typeCLASS, typeCLASS_f, nColors, n_byteOffset, n_bands, registration;
287287
int is_geog = 0, gdal_err = 0;
288288
uint64_t nn, ijk = 0;
@@ -582,16 +582,17 @@ int gmt_gdalwrite (struct GMT_CTRL *GMT, char *fname, struct GMT_GDALWRITE_CTRL
582582
}
583583

584584
if (!prhs->H.active && gmt_strlcmp(pszFormat,"netCDF")) { /* Change some attributes written by GDAL (not finished) */
585-
int ncid, err;
586-
gmt_M_err_trap (nc_open (fname, NC_WRITE, &ncid));
587-
gmt_M_err_trap (nc_put_att_text (ncid, NC_GLOBAL, "history", strlen(prhs->command), prhs->command));
588-
gmt_M_err_trap (nc_close (ncid));
585+
int ncid;
586+
error = nc_open (fname, NC_WRITE, &ncid);
587+
error += nc_put_att_text (ncid, NC_GLOBAL, "history", strlen(prhs->command), prhs->command);
588+
error += nc_close (ncid);
589+
if (error) GMT_Report(GMT->parent,GMT_MSG_ERROR,"Error adding history: %d\n", error);
589590
}
590591

591592
gmt_M_free(GMT, outByte);
592593
if (pszSRS_WKT != NULL) CPLFree(pszSRS_WKT);
593594
if (papszOptions != NULL) CSLDestroy (papszOptions);
594595
GDALDestroyDriverManager();
595596

596-
return (GMT_NOERROR);
597+
return error;
597598
}

src/gmt_init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17449,6 +17449,7 @@ int gmt_add_figure (struct GMTAPI_CTRL *API, char *arg, char *parfile) {
1744917449
snprintf (file, PATH_MAX, "%s/gmt.movie%ss", API->gwf_dir, F_name[k]);
1745017450
if ((fpM[k] = fopen (file, "w")) == NULL) {
1745117451
GMT_Report (API, GMT_MSG_ERROR, "Cannot create file %s\n", file);
17452+
fclose (fp);
1745217453
return GMT_ERROR_ON_FOPEN;
1745317454
}
1745417455
fprintf (fpM[k], "# movie %s information file\n", F_name[k]);

0 commit comments

Comments
 (0)