tweaks: don't leave an orphaned temporary file behind when writing fails

This commit is contained in:
Benno Schulenberg 2022-03-27 12:34:32 +02:00
parent 803ea0d7a0
commit 3def429290

View File

@ -2528,6 +2528,7 @@ void do_spell(void)
if (!okay) {
statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
unlink(temp_name);
free(temp_name);
return;
}
@ -2924,13 +2925,10 @@ void do_formatter(void)
if (temp_name != NULL)
okay = write_file(temp_name, stream, TEMPORARY, OVERWRITE, NONOTES);
if (!okay) {
if (!okay)
statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
free(temp_name);
return;
}
treat(temp_name, openfile->syntax->formatter, FALSE);
else
treat(temp_name, openfile->syntax->formatter, FALSE);
unlink(temp_name);
free(temp_name);