@@ -218,6 +218,31 @@ recode_transform_byte_to_variable (RECODE_SUBTASK subtask)
218218 SUBTASK_RETURN (subtask );
219219}
220220
221+ /*-------------------------------------------------------------------.
222+ | Close the subtask input file pointer if it is owned by librecode. |
223+ `-------------------------------------------------------------------*/
224+
225+ static bool
226+ close_subtask_input (RECODE_SUBTASK subtask )
227+ {
228+ if (subtask -> input .file )
229+ {
230+ if (subtask -> input .file && subtask -> input .name &&
231+ subtask -> input .name [0 ])
232+ {
233+ if (fclose (subtask -> input .file ) != 0 )
234+ {
235+ recode_perror (NULL , "fclose (%s)" , subtask -> input .name );
236+ recode_if_nogo (RECODE_SYSTEM_ERROR , subtask );
237+ return false;
238+ }
239+ }
240+
241+ subtask -> input .file = NULL ;
242+ }
243+ return true;
244+ }
245+
221246/*------------------------------------------------------------------------.
222247| Execute the conversion sequence for a recoding TASK. If no conversions |
223248| are needed, merely copy the input onto the output. |
@@ -327,18 +352,8 @@ recode_perform_task (RECODE_TASK task)
327352
328353 /* Post-step clean up for memory sequence. */
329354
330- if (subtask -> input .file )
331- {
332- FILE * fp = subtask -> input .file ;
333-
334- subtask -> input .file = NULL ;
335- if (fclose (fp ) != 0 )
336- {
337- recode_perror (NULL , "fclose (%s)" , subtask -> input .name );
338- recode_if_nogo (RECODE_SYSTEM_ERROR , subtask );
339- goto exit ;
340- }
341- }
355+ if (!close_subtask_input (subtask ))
356+ goto exit ;
342357
343358 /* Prepare for next step. */
344359
0 commit comments