From 14e92ae17ea68adfe8d703b740e20c7f368138fb Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 20 Jun 2020 07:17:06 +0200 Subject: [PATCH] Don't ref or unref the inline file handle. The special file handle 'inline_file' is a singleton. It should not be reffed, or unreffed. Doing so causes a crash. Reported by Andrea Fioraldi. Fixes bug #58601 --- src/data/file-handle-def.c | 9 +++++++++ tests/data/file.at | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index 1296a5b171..716a029cc7 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -115,12 +115,17 @@ fh_done (void) HMAP_FOR_EACH_SAFE (handle, next, struct file_handle, name_node, &named_handles) unname_handle (handle); + + free_handle (inline_file); } /* Free HANDLE and remove it from the global list. */ static void free_handle (struct file_handle *handle) { + if (handle == NULL) + return; + /* Remove handle from global list. */ if (handle->id != NULL) hmap_delete (&named_handles, &handle->name_node); @@ -153,6 +158,8 @@ unname_handle (struct file_handle *handle) struct file_handle * fh_ref (struct file_handle *handle) { + if (handle == fh_inline_file ()) + return handle; assert (handle->ref_cnt > 0); handle->ref_cnt++; return handle; @@ -165,6 +172,8 @@ fh_unref (struct file_handle *handle) { if (handle != NULL) { + if (handle == fh_inline_file ()) + return; assert (handle->ref_cnt > 0); if (--handle->ref_cnt == 0) free_handle (handle); diff --git a/tests/data/file.at b/tests/data/file.at index 6fcbe579aa..d3013d7501 100644 --- a/tests/data/file.at +++ b/tests/data/file.at @@ -120,3 +120,21 @@ x,y ]) AT_CLEANUP + + +dnl This was seen to crash pspp +AT_SETUP([Reusing inline file]) + +AT_DATA([inline-reuse.sps], [dnl +get data /type=txt /file=inline /variables=A f7.2 . + +data list notable list /foo. +begin data. +end data. + +data list notable list /foo. +]) + +AT_CHECK([pspp inline-reuse.sps], [0], [ignore]) + +AT_CLEANUP -- 2.30.2