Skip to content

Commit

Permalink
If no input to greenspline then properly quit (#8048)
Browse files Browse the repository at this point in the history
* If no input to greenspline then properly quit

Instead we got a SEGV trail due to n == 0. Closes #8040.

* Also fix memory leak in surface
  • Loading branch information
PaulWessel authored Nov 18, 2023
1 parent 3a3c000 commit 2b0cfcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/greenspline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,13 @@ EXTERN_MSC int GMT_greenspline (void *V_API, int mode, void *args) {
Return (API->error);
}

if (n == 0) { /* Empty input file */
for (p = 0; p < n; p++) gmt_M_free (GMT, X[p]);
gmt_M_free (GMT, X); gmt_M_free (GMT, obs);
GMT_Report (API, GMT_MSG_ERROR, "No data records found - aborting!\n");
Return (GMT_RUNTIME_ERROR);
}

X = gmt_M_memory (GMT, X, n, double *);
obs = gmt_M_memory (GMT, obs, n, double);
nm = n;
Expand Down
1 change: 1 addition & 0 deletions src/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ GMT_LOCAL int surface_read_data (struct GMT_CTRL *GMT, struct SURFACE_INFO *C, s

if (C->npoints == 0) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "No datapoints inside region, aborting\n");
gmt_M_free (GMT, C->data);
return (GMT_RUNTIME_ERROR);
}

Expand Down

0 comments on commit 2b0cfcf

Please sign in to comment.