diff --git a/src/greenspline.c b/src/greenspline.c
index c068f984e2e..7277da68ad0 100644
--- a/src/greenspline.c
+++ b/src/greenspline.c
@@ -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;