- writer->handle->casereader = reader;
- fh_close (writer->fh, "scratch file", "we");
+ {
+ /* Destroy previous contents of handle. */
+ struct scratch_handle *sh = fh_get_scratch_handle (writer->fh);
+ if (sh != NULL)
+ scratch_handle_destroy (sh);
+
+ /* Create new contents. */
+ sh = xmalloc (sizeof *sh);
+ sh->unique_id = ++next_unique_id;
+ sh->dictionary = writer->dict;
+ sh->casereader = reader;
+ fh_set_scratch_handle (writer->fh, sh);
+ }
+ else
+ {
+ casereader_destroy (reader);
+ dict_destroy (writer->dict);
+ }
+
+ fh_unlock (writer->lock);
+ fh_unref (writer->fh);